nm

11488 Reputation

20 Badges

13 years, 85 days

MaplePrimes Activity


These are replies submitted by nm

Example 1, under "Improved handling of piecewise, eval/diff in the given problem" has an inconsistent boundary and initial conditions?

At x=0, initial coditions says that f should be 1.

But boundary conditions says at x=0, f is zero.

If I can provide a small improvement to the specifications of PDE's.

1) It is better to keep order of independent variables as  space first and time last,
i.e. as (x,t) in all the problems as this is much more common.

This problem uses the (t,x) order, but all others used the common order (x,t).

Having the same order for all problems reduces errors and possible confusion.

2) It makes it more clear if the initial and boundary conditions are written in two separate variables, one called ic:=... and the other called bc:=... instead of how it is currently written in one variable iv:=...

This makes it more clear to spot and read what are the initial conditions and what are the boundary conditions.

thanks

@Preben Alsholm 

Thanks. It works very well.

Thank you for the updates to pdsolve.

For example 4, Mathematica gives a simpler answer to example 4 above. Both Maple and Mathematica answers seems equivalent. I plotted them for random time and they look at the same.  So I am assuming they are both correct for now.

I tried to simplify Maple's solution but could not. Maybe you can suggest how to simplify Maple answer to look like Mathematica's.

restart;
f := x->3*cos(42*x*Pi);
g :=(x,t)->exp(3*t)*cos(17*x*Pi);
pde := diff(u(x, t), t)= (diff(u(x, t), x, x)) + g(x, t);
bc := (D[1](u))(0, t) = 0, (D[1](u))(1, t) = 0;
ic:= u(x, 0) = f(x);
sol:=pdsolve([pde, ic, bc]);

gives

In Mathematica

ClearAll[u,t,x,f,g];
f[x]:=3*Cos[42*Pi*x];
g[x,t]:=Exp[3*t]*Cos[17*x*Pi];
pde=D[u[x,t],t]==D[u[x,t],{x,2}]+g[x,t];
bc={Derivative[1,0][u][0,t]==0,Derivative[1,0][u][1,t]==0};
ic=u[x,0]==f[x];
sol=DSolve[{pde,bc,ic},u[x,t],{x,t}]

It gives

{{u[x, t] -> (E^(3*t)*Cos[17*Pi*x])/(3 + 289*Pi^2) - 
    Cos[17*Pi*x]/(E^(289*Pi^2*t)*(3 + 289*Pi^2)) + (3*Cos[42*Pi*x])/
     E^(1764*Pi^2*t)}}

Thanks

@Carl Love 

But making changes to list or sets once constructed is very common. I can come up with 1,000 cases where this is needed.

lets say I have a list of expressions. Now I want to iterate over the list and make some substituion to each entry if needed based on some information obtained after the list of expressions were created, and so on.

May be I need to change my data from using set {} in Maple to something else which is mutable so I can use [i] syntax on it. I will look at using Array instead.

I am newbie in Maple, and now just use list and set. sometimes I used Matrix.

@acer

If I understand you right, you seem to be saying the different syntax is used/needed to remind a user that the set or list being modified is immutable?

In Mathematica a list is also immutable, but one still do "A[[1]]=something". Internally Mathematica makes a copy, changes the copy and replaces the original with the modified copy. There is no need for new syntax.

In[207]:= lst={1,2,3};
lst[[1]]=0;

lst
    Out[209]= {0,2,3}

I do not see how is this any different from Maple's

             A = subsop(1=something,A)

where a new copy is made of the original and returned  to caller. So, In both cases a new copy must be made anyway to make any changes. With Mathematica, it is done under the cover, while with Maple it is done above the cover.

Only difference is that the syntax "A[i]=something" is much more natural to use.

Exposing to the user that the a list or set is immutable by forcing different syntax to be used for such a very common operation is not a good language design IMHO.

@Carl Love 

 

" Your Mathematica example doesn't look so great to me! The spacing is awkward, and the 2 is not superscripted. "

Sorry I was not clear. The Mathematica Latex output still needs to be compiled by pdflatex, which I did not bother doing like I did with Maple as it was clear it is correct Latex, but here it is after compiling it in Latex

In[22]:= expr= y[x]^2;
TeXForm[expr]

Out[23]//TeXForm=
         y(x)^2

Which renders as (after compiling)

 

side by side

@Carl Love 

" There's no difference between sin(s)^2 and (sin(s))^2. The latter simply has superfluous parentheses (which I personally find to be a significant annoyance when I'm trying to read code). "

That is all true. That is why I hate it when Maple insists on adding the extra parentheses when converting to Latex.

expr:=y(x)^2:
latex(expr);

           \left( y \left( x \right)  \right) ^{2}

which renders as

Compare to Mathematica

Which renders as, well, as it shows above. No extra ugly () needed.

Maple Latex rendering of math is broke for many many years. Yet Maplesoft claims Maple is for Mathematicians.

 

@Carl Love 

 

"You don't need to return anything because the statement r:-b:= 5 inside foo has already changed the global r"

Ah. So Maple passed the Record variable by reference. That is why when I updated it inside the function, it updates the global one also. 

I thought at first it passes a copy of the Record variable, that is why after i modified it, I did explicit return. I had no idea it passed it by reference here.

This is a bit confusing.  How does one know when Maple passes parameters by Value and when it passes by reference? I thought Maple passes everything by Value like with Mathematica. Ok. I found that Maple pass rtables by reference. and Record is of this type. That is why.

How to force a copy to be passed for rtable based struct such as Matrix, Record, etc...?  I did foo(eval(r)): but it still passed it by reference. 

I want to pass by value "r", so changes inside the function do not update the global variable with same name. 

thanks

 

 

 

There are many ways to iterate over data. You have not explained what data structure your data is contained in. Better to make a MWE always.

 

Try looking up 'for' which is used for a loop. something like

for item in z do
     process(item)
od;

or

for n from 1 to nops(z) do
     process(z[n])
od;

etc...

@tomleslie 

yes I did. I always look at help. I did see the use of :: which I tried and did not work. The opaquemodules= false was burried deep inside a long page of writing and I must have missed it. Not that I even know what it means being a newbie in Maple.

I find Maple help pages the worst part abut Maple as they are very hard to read. The formatting and the way help page are organised makes them hard to read.  One has to read pages and pages of stuff looking for something.

Such things in Mathematica are put in special section called "possible issues" where it is easy to spot.

@Carl Love 

" The first is to replace :- with :: in the stopat command "

I tried

stopat(foo::foo1::foo2);
Error, ambiguous use of `::`, please use parentheses

stopat(foo::(foo1::foo2));
Error, (in stopat) procedure name expected

But this worked !

stopat((foo::foo1)::foo2);

Also your second solution seems to work.

      kernelopts(opaquemodules= false);
     stopat(foo:-foo1::foo2);

Thank you

 

Mathematica seems to be fast doing these. 10^12 takes 20 seconds.

Prime[n] gives the n^th prime number. The numbers in the first entry returned in the seconds used.

@vv 

"For example F(x,y) = x * ( y + x*sqrt(x*y) + sqrt(x^3*y) )
can be split only for x<0,
"

Yes, good point. So I guess I have to assume x>0 for all test cases. This is in the context of solving a first order ODE by separation. So suppose the ODE was

               y'(x) = F(x,y)

and F(x,y) was your function above. If one can separate it, then the ODE becomes easy to solve. But most HW problems normally do not say x>0, but I think it is safe to assume this. Unless otherwise stated. I need to worry about this.

btw, your F seems to give dsolve hard time.

@Kitonum 

I implemented this `` trick in what follows. It gets little tricky, since I have to watch out for op(1,op(1... all the times. Does this look ok for you? 

Given sqrt(1-y^2)/x; I want to write is as sqrt(|1-y^2|)/x; and then remove || to obtain the original expression back. Using subsindents. So I wrote

restart;
Y:=sqrt(1-y^2)/x;
Y:=subsindets(Y,anything^({1/2,-1/2}),ee->abs(``(op(1,ee)))^(op(2,ee)));     
Y:=subsindets(Y,abs(anything)^(1/2),ee -> op(1,op(1,op(1,ee)))^op(2,ee));

Which works. I am just getting little dizzy counting ops in op(1,op(1,op(1,ee)))^op(2,ee) to get it right.

I wish there was a simple way for Maple to just leave what is inside abs() the way it was and not muck it up.

 

@Carl Love 

fyi, I found some problems.

expr:=sqrt(1-y^2)/(2*sqrt(x));
r:=Separate(expr,[x,y]);

It should be  sqrt(1-y^2) and 1/(2*sqrt(x)). And

 

expr:=sqrt(1-y^2)/x;
r:=Separate(expr,[x,y],method=tryhard);

The result should be   sqrt(1-y^2) and 1/x

And

expr:=sqrt(1-y^2);
r:=Separate(expr,[x,y],method=tryhard);

It should be  1 * sqrt(1-y^2).

I think these all are from same "issue". Having complex numbers pop up like this, makes it hard to use. I will add these cases to the list of cases in my original post now.

I am sure there is a way to simplify the result obtained back to what it should be with assumptions and combine(...,radical). So the output is not wrong, but hard to use as is. A post-processing step is now needed.

thanks

 

 

First 67 68 69 70 71 72 73 Last Page 69 of 91