6246 Reputation

17 Badges

9 years, 63 days

MaplePrimes Activity

These are replies submitted by nm


I found a case where PDEtools:-Solve can't solve for the unknowns in the equation. May be I am not understanding  some of the functionality. It works on some equations but not on others, when I was testing it. Here is an example where it can not solve it

eq:=-4*c1*sin(2*x)+4*c2*cos(2*x)+2*c3*cos(2*x)-8*c3*x*sin(2*x)+2*c4*sin(2*x)+8*c4*x*cos(2*x) = 3*x*cos(2*x);
the_constants:={c1, c2, c3, c4};
PDEtools:-Solve(eq,the_constants,independentof = x);

Here it seems to hang. Waited for more than one hr. While

eq:=-4*c1*sin(2*x)+4*c2*cos(2*x)+2*c3*cos(2*x)-8*c3*x*sin(2*x)+2*c4*sin(2*x)+8*c4*x*cos(2*x) = 3*x*cos(2*x);
sol := solve(identity(eq,x),{c1,c2,c3,c4});

Gives the answer immeadiatly

Also Solving this by "hand", by comparing terms gives

the_constants:={c1, c2, c3, c4};

Here is an example where it works:


Which agrees with the "manual" solution

PDEtools:-Solve([eq1,eq2,eq3],{c1, c2, c3});

Why did the first example above not solve it?


@Preben Alsholm 

        "This works:"

I am afraid it does not work.

select(type,expr,identical(x^2) &* anything);

gives 0

Maple 2021.1



@Joe Riel 

             "Try changing anything to indexed"

this does not really help. First, it has to work for any expression. I do not know what is being multiplied by x^2. This was just an example.

select(type,expr,'`*`'({anything, identical(x^2)}));

gives 3*x also. I needed something similar to pattern matching





does not as expected.     But need to do it using structured types, just to learn it better as it is "supposed" to be the better way to do this, but I find it much confusing than using simple patterns.



@Rouben Rostamian  

You don't want u(0,theta)=0.  You want u(0,theta) to be finite. 

Yes, I knew that, but I did not know how to tell Maple that u(0,theta) is "finite". So I used zero to see what solution it gives.

When solving by hand, we can do that, but I do not think it is possible to tell the computer this. At least  I do not know how to.



@Joe Riel 

thanks both. I forgot about satisfies. Yes, this should do it.



And if I tell it u=0 at r=0, then one of the BC is not satisfied

the_rhs := r^2*cos(theta)*sin(theta):
pde := VectorCalculus:-Laplacian(u(r,theta),'polar'[r,theta])=the_rhs:
bc := u(1, theta) = cos(theta)*sin(theta),u(0,theta)=0;
sol:=pdsolve([pde, bc], u(r, theta),HINT=f(r)*sin(2*theta));


As the solution blows at r=0



I tried your other hint, and it gives this solution

the_rhs := r^2*cos(theta)*sin(theta):
pde := VectorCalculus:-Laplacian(u(r,theta),'polar'[r,theta])=the_rhs:
bc := u(1, theta) = cos(theta)*sin(theta):
sol:=pdsolve([pde, bc], u(r, theta), HINT=f(r)*sin(2*theta));

In plain text

sol := u(r, theta) = ((r^6 + 24*_C2*r^4 - 24*_C2 + 11)*sin(2*theta))/(24*r^2)

which seems closer to the correct one, but not exactly the same. Notice it has also one unknown _C2

and using 

sol:=pdsolve([pde, bc], u(r, theta), HINT=f(r)*g(theta));


sol := u(r, theta) = sin(2*theta)*(-576*_C2*_C3^4*r^4 + 24*_C3^3*r^6 + 264*_C3^3*r^4 + _C3*r^6 + 576*_C2*_C3^4 + _C2*r^4 - _C2 + 11*_C3)/(576*_C3^3*r^2 + 24*_C3*r^2)



thanks., but in Maple 2021 HINT=`*` returns the same solution as without this hint.

the_rhs := r^2*cos(theta)*sin(theta):
pde := VectorCalculus:-Laplacian(u(r,theta),'polar'[r,theta])=the_rhs:
bc := u(1, theta) = cos(theta)*sin(theta):
sol:=pdsolve([pde, bc], u(r, theta), HINT=`*`);


@Rouben Rostamian  

Thanks. Yes, this can be solved by hand analytically (I did not do that), but got the solution from Mathematica, which is the same as the one you showed. That is why I was surprised that Maple gives, what looks like wrong solution here.

rhs=r^2 Cos[theta]*Sin[theta];
soldsolve=u[r,theta]/. First@DSolve[{pde,bc},u[r,theta],{r,theta}]

Here is a plot of the solution

It is possible Maple can solve it analytically and give the correct solution using some Hints or other options I do not know about.,



I was testing the last one, but it does not work?


it gives

But the method with try/catch worked.



Yes, this helped reduce verbosity in this example, but still due to not able to use "zero or more" method in general with structured type, I find I still need to duplicate things.

Let me give a much simpler example than the above. 

Suppose we want to match  anything*sin(anything)  by making a structured type for this expression.

Since I can't use zero or more, I find I have to duplicate the type using Or or {}.

One time for anything*sin(anything) when anything is not 1, and one for sin(anything) for the case when factor is default 1. Here is an example

TypeTools:-AddType('my_type', {  '`*`'({rational,specfunc(sin)}),   specfunc(sin)   } );

The above structured type now matches both cases. Because the first part looks for `*` type and the second one looks for sin(x) on its own. So I had to make separate type for when the leading factor is default 1. Same thing for powers if present like in the example I posted in original post.

I know ofcourse that 2*sin(x) has type `*`  and sin(x) is not type `*` that is why it does not work. Which is completely understandble from point of view of a strong type system. But for finding subexpressions, it means one have to make many types to capture each possible case, while with pattern matching (which does not use structured types), one can, using only one pattern, match a much larger class of subexpressions.

In Mathematica, using the zero or more method for pattern:

type = n_.*Sin[_];
MatchQ[Sin[x], type]
MatchQ[2*Sin[x], type]

And both above gives True match since first one, n_. says zero or more. No need to duplicate things.

I can do the same thing above using Maple's patmatch easily as follows

patmatch(2*sin(x),my_pattern,'la'); la;
patmatch(sin(x),my_pattern,'la'); la;

But I can't do similar thing with structured type. That is why I think patterns are more flexible for finding subexpressions and for expressions transformation, but everyone here says to avoid patmatch in Maple and use structured types.


You should read the question before answering.

I know everything you said and I mentioned that in the question itself. 

I simply was asking if there is a way to do a select or select like function that starts at top level and go down. I currently do a type check first and if that fail, then call select.





I actually tried identical(x) as you can see from my post. The problem is that I had {} in there. That is why it did not work.  This is what I tried (copied from my post)

lis:=indets(expr,  Or( And(type_1),  And(type_2) ))

The above did not work. it gives

Changed the code to remove the {} now it works

lis:=indets(expr,  Or( And(type_1),  And(type_2) ))

So I was close (but no cigar). But because I used a list instead of expression sequence, it did not work.



Thanks, this works. I got confused since I thought I have to have a Maple type in there. And  identical(x) is not a "type" in Maple sense? (as in integer, function, real, symbol, etc...). But good one can supply this. I did not know that before.



But this adds the symbol x even it does not exist!


indets(expr, function) union {x};


Which is wrong.


1 2 3 4 5 6 7 Last Page 1 of 55