annamiaswart

20 Reputation

3 Badges

5 years, 31 days

MaplePrimes Activity


These are questions asked by annamiaswart

Dear all,

I cannot quite seem to figure out what it is that I am doing wrong. In the plots that I am trying to plot, I keep getting an error "Error, bad index into Matrix". I understand what the error means (having read through the webpage that it takes me to), but I cannot figure out what my mistake is. Can someone please help me understand what I am doing wrong?

Simple_Plot.mw

Dear all, 

Yesterday I asked a very similar question, but i thought about it and found a different way to re-phrase my question:

Given a plot with three dependent variables that depend on one independent variable, how can I extract this data into a .xls (or .dat or whatever) file for re-use in Maple later on? The .xls will have to have 4 columns: the first for the independent variable and the next three for the dependent variables.

Find my worksheet here: worksheet.mw

I managed to write a program that extracts the data into a .dat file, but with only two columns. 

The reason that I want to do this is because I want to re-use the solutions to the variables and the derivatives in a different equation (for plotting). For example q(z) = ( diff(h1(z),z)+ diff(h2(z),z)+ diff(h3(z),z))/(h1(z) +h2(z) +h3(z)), and then z versus plot q(z). Any alternative suggestions would be helpful.

Dear all,

I have 3 ODE's that I solved with the use of a for loop that cycles through different IC's. The purpose of this is so that I can compare the solutions with different IC's. I have three dependent variables (h1(z), h2(z), h3(z)), and one independent variable (z). The loop that I created looks like this:

_Omega_r := 10^(-5);
n := 10;
for i from 0 to n do:
    h10[i] := 1-0.16666667e-1*i;
    h20[i] := 1-(.7*0.16666667e-1)*i;
    h30[i]:= 3-h10[i]-h20[i];
    ans := dsolve([eq2, eq3, eq4, h1(0) = h10[i], h2(0) = h20[i], h3(0) = h30[i]], {h1(z), h2(z), h3(z)}, numeric, output = listprocedure);
    h1_sol[i] := rhs(ans[2]);
    h2_sol[i] := rhs(ans[3]);
    h3_sol[i] := rhs(ans[4]);
    print(i);
end do

Here, h10[i], h20[i] and h30[i] are my initial conditions. I use h1_sol[i], h2_sol[i] and h3_sol[i] to make plots of the solutions:

I make two different types of plots - one type has only the different solutions for h1(z) with all initial conditions:

h1plot := plot([seq(h1_sol[i](z), i = 0 .. 10)], legend = [h1(0) = h10[0], h1(0) = h10[1], h1(0) = h10[2], h1(0) = h10[3], h1(0) = h10[4], h1(0) = h10[5], h1(0) = h10[6], h1(0) = h10[7], h1(0) = h10[8], h1(0) = h10[9], h1(0) = h10[10]], title = "z versus h1(z) for different initial conditions", labels = ["z", "h1(z)"]);

And the other uses one set of initial conditions, but all three h1(z), h2(z), h3(z):

allplot1 := plot([seq(h1_sol[i](z), i = 2), seq(h2_sol[i](z), i = 2), seq(h3_sol[i](z), i = 2)], title = [typeset(h(z), " versus ", z, " (case 2)")], labels = [z, h(z)], legend = [typeset(h[1](z), " with ", h1__0 = h10[2]), typeset(h[2](z), " with ", h2__0 = h20[2]), typeset(h[3](z), " with ", h3__0 = h30[2])]);

Now, all of this works wonderfully. I managed to do everything I wanted. Except that I have been struggling figuring out how to extract the data from the plots into a .dat file into different columns. With the code that I did write, if I use it on the first plot, I end up getting 2 columns, one for z and one for h1(z) (for example), but there should be 11 columns (one for z and 10 for h1(z) with different initial conditions). How would I go about to extract the data of multiple plots into one .dat (or .xls, or .csv or whatever) file? What I did:

write := proc (plotname, filename)
    local fd; fd := fopen(filename, WRITE, TEXT);
    writedata(fd, convert(op([1, 1], plotname), matrix));
    fclose(fd);
end;

write(h1plot, `zvsh1GR.dat`)

Alternatively, if there is a way to use the solution in Maple directly without extracting first (I need to use the solutions for h1(z), h2(z), h3(z) to plot different equations that are dependent on these variables), that would be great. For example, I would like to use these three variables in an equation that uses both the derivatives of all three the variables and the variables themselves as is. For example:

q (z)= (diff(h1(z),z)+diff(h2(z),z)+diff(h3(z),z))/(h1(z)+h2(z)+h3(z))

And then I want to plot q(z) vs z.

I'm sorry if this is a lengthy question (or one with a simple solution) - I am still learning Maple.

My Maple file:
Solving_GR_f(R)_ne_2.maple

Maple worksheet: Solving_GR_f(R)_ne_2.mw

Hi. I am trying to solve a system of differential equations but I am having trouble understanding what I do wrong. I am a novice Maple user.

>with(PDEtools): with(LinearAlgebra): with(DifferentialGeometry): with(VectorCalculus): with(DEtools):

>_Omega_d := 1-_Omega_r

>eq1 := h1(z)*h2(z)+h2(z)*h3(z)+h1(z)*h3(z)-3*(_Omega_d*((1+z)^3)+_Omega_r*((1+z)^4)) = 0

>eq2 := h2(z)^2+h3(z)^2+h2(z)*h3(z)-1/3*(1+z)*(h2(z)*(diff(h2(z), z))+h3(z)*(diff(h3(z), z)))+_Omega_r*((1+z)^4) = 0

>eq3 := h1(z)^2+h3(z)^2+h1(z)*h3(z)-1/3*(1+z)*(h1(z)*(diff(h1(z), z))+h3(z)*(diff(h3(z), z)))+_Omega_r*((1+z)^4) = 0

>eq4 := h2(z)^2+h1(z)^2+h2(z)*h1(z)-1/3*(1+z)*(h2(z)*(diff(h2(z), z))+h1(z)*(diff(h1(z), z)))+_Omega_r*((1+z)^4) = 0

>sys := {eq2, eq3, eq4}

Equations eq1 - eq4 are my equations, but since eq1 does not have a differentiated function, I leave it out of the system, otherwise I get an error that states that I have more functions than variables.

>sys1 := subs(_Omega_r = 10^(-15), sys)

>ics := {h1(0.1e-3) = 1, h2(0.1e-3) = 1, h3(0.1e-3) = 1, (D(h2))(0.1e-3) = 4.500015, (D(h3))(0.1e-3) = 4.500015, (diff(h1(z), z))(0.1e-4) = 4.500015}

ics are my inititial conditions.

>pdsolve(sys1 union ics, {h1(z), h2(z), h3(z)}, type = numeric, generalsolution)

But when I run this, I get an error that says "Error, (in pdsolve/sys) found the independent variables {z} also present in the names of the functions of the system {}".

I have tried numerous different methods to solve this, and I get stuck every time. If anyone has any advice, I would appreciate it. I am trying to get solutions for h1(z), h2(z), h3(z) (to ultimately plot these functions versus z), if possible.

 

Page 1 of 1