nm

11353 Reputation

20 Badges

13 years, 20 days

MaplePrimes Activity


These are questions asked by nm

This is an ode from text book.  The little tricky part on this is the right hand has abs on the dependent variable, otherwise it is trivial.

restart;
ode:=diff(y(x),x) = abs(y(x))+1;
sol:=dsolve(ode,y(x))

Gives

I am not able to get odetest to give zero on either of the two solutions.  

odetest(sol[1],ode);
odetest(sol[2],ode);

None give zero. I tried assumptions on x>0, x<0 and tried simplify(...,symbolic), nothing gives zero.

Now the book gives the solutions without constant of integration, which is strange. This is what the book gives as solution

                 y(x) = exp(x)-1   x>=0
                 y(x) = 1-exp(-x) x<0

Which is the same as Maple's solution, but without the constant of integration! So when I removed _C1 from both solutions and added the assumptions on x, then I got zero

odetest(subs(_C1=1,sol[1]),ode) assuming x<0;
                      0

odetest(subs(_C1=1,sol[2]),ode) assuming x>=0
                      0

I solved this by hand, and got same solution as Maple actually (may be I made the same mistake as Maple? :) 

But the above shows these solution are not correct? I do not now know what happend to the constant of integration in the book solution since it only shows final solution. It looks like book just used C=1 for the constant of integration. But Maple also thinks the book solution is correct.

fyi, the implicit solution by Maple does verify with no problem:

ode:=diff(y(x),x)=abs(y(x))+1;
sol:=dsolve(ode,y(x),'implicit');
odetest(sol,ode)

             0

Any one can shed some light what is going on? Is Maple solution correct? If so, why it does not verify? Should Maple have given the book solution?

this is problem 9, page 15, "Elementary differential equations" by William F. Trench, 2001

Maple 2019.1

given an expression such as expr:=-1/2*x*(y^2-1) which in tree form will be

I can get -1/2 using op(1,expr).   I need command to return the "rest" of the right side of the tree, all of it, not matter how big.

I tried op(2..nops(expr),expr) and that returns x, y^2 - 1 

Is there a way to return directly x*(y^2-1)*etc....  so I do not have to play around with the above expression sequence?  Another option is to type

           expr/op(1,expr)

to get the right side of the tree. But this seems like a hack. Do not like to divide. worry about zero.

The same thing if the type was `+`, I want to get  the whole right side in one command.

Again, I can do  expr-op(1,expr) to get the whole right side. But this also seems like  a hack, altought not as bad as with  the case above

Any hints on how to best do these things?

Maple 2019.1

 

 

 

I never used applyrule before. Seems like a good command. I was trying to tell Maple to rewrite

as

I could not find one command to do it.  Collect does not work. The only way I figure to it, is by replacing 

by a new single unused symbol, and then use collect on the symbol, then use subs again to replace the symbol with orginal  expression. like this

restart;
expr:=(x^2 - 1)/x^2*y + (x^2 - 1)/x^2;
r:=(x^2 - 1)/x^2; #this is what I want to collect
applyrule(r=Z,expr);
collect(%,Z);
subs(Z=r,%)

In the above code, if I replace applyrule by algsubs, it does not work. Why?

restart;
expr:=(x^2 - 1)/x^2*y + (x^2 - 1)/x^2;
r:=(x^2 - 1)/x^2;
algsubs(r=Z,expr);

You see, it did not replace (x^2-1)/x by Z, like applyrule does:

restart;
expr:=(x^2 - 1)/x^2*y + (x^2 - 1)/x^2;
r:=(x^2 - 1)/x^2;
applyrule(r=Z,expr);

I will learn applyrule now more to do this. I was just wondering why algsubs failed, and if applyrule is the better tool to do this. Or may be there is a better way to do this whole thing?

Maple 2019.1

I made a typo below, I did not mean to put [...] around the solution. But why Maple throws an error on this only?

restart;
ode:=diff(y(x),x) = exp(x)*sin(x)+y(x)*cot(x);
my_sol:=[sin(x)*(exp(x)+_C1)];
odetest( y(x)=my_sol,ode) assuming x::real

          Error, (in type/algext) too many levels of recursion

But on other ODE's, it works

restart;
ode:=diff(y(x),x) = y(x);
my_sol:=[_C1*exp(x)];
odetest( y(x)=my_sol,ode) assuming x::real

                [0]

I'll correct my type and remove the []. But the question is, should Maple have thrown an error? And why only on this one? Would this be considered a bug?

Removing the [] from the first example above, the error is gone and 0 is returned.

Maple 2019.1, Physics V 395 on windows 10

I thought I remembed how to do this once in Maple, or asking something like this here, but may be it was something similar. But I am not able to figure it now or remember.

Given an expression, I want to find all occuranes of a pattern in it.  Not just one.  So this is like using patmatch but over and over again untill all patterns found. I'll give an example to make it easy to explain.

Given

expr := y^2*sin(1/y) + y^(3/2) + y + x*y^7;

I want to find all patterns of form y^n  so the result should be 

{y^(3/2), y^7, y^2, 1/y, y}

This below is how it is done in Mathematica, but having hard time translating this code to Maple.

The last line below does the actual repeated pattern matching. That line was not written by me. It is something from Mathematica forum at stackexchange and I use it all the time and it works well.

ClearAll[x,y,n]
expr = y^2*Sin[1/y] + y^(3/2) + y + x*y^7;
pat = y^n_.;
Last@Reap[expr /. a : pat :> Sow[a], _, Sequence @@ #2 &]

I looked at hastype also. But hastype will only tell me if the pattern is there or not. May be I did not use it right.

restart;
expr := y^2*sin(1/y) + y^(3/2) + y + x*y^7;
hastype(expr,symbol^(anything));

Gives true

I tried patmatch, but again, it only find one:

restart;
expr := y^2*sin(1/y) + y^(3/2) + y + x*y^7;
if patmatch(expr,a::anything+y^(n::anything)+b::anything,'la') then
   assign(la);
   n;
fi;

And the above is not even robust for finding one. Since I have to change the pattern again to account for multiplication/addition cases between terms. 

Is it possible to do in Maple the same thing I show in Mathematica? I am sure it is possible, but can't now find the right function in Maple.

Maple 2019.1

First 137 138 139 140 141 142 143 Last Page 139 of 199