nm

2561 Reputation

16 Badges

7 years, 39 days

MaplePrimes Activity


These are questions asked by nm

8/24/19. Updated question the bottom

I need to find if expression has  a "-" in front of it or not.  This is for formatting purposes for something I am doing, that is all. 

I was using the command sign() for this, and it seems to work OK, but sometimes a Maple error is generated or not leading term sign is returned.

The sign function computes the sign of the leading coefficient of expr.

Is there a better and more robust way to do this other than using sign() or Am I using sign wrong?

restart;

expr:=-sin(x)/ln(y)+1;
op(expr);

-sin(x)/ln(y)+1

-sin(x)/ln(y), 1

#why this gives 1 as sign for the above?
sign(expr);

1

#workaround?
sign(op(1,expr))

-1

expr:=sin(x)/ln(y)+1;
sign(expr);

sin(x)/ln(y)+1

1

expr:=-x;
sign(expr);

-x

-1

expr:=-LambertW(exp(p))+1;
sign(expr)

-LambertW(exp(p))+1

-1

expr:=-LambertW(exp(p))/(1+LambertW(exp(p)))+1;
sign(expr)

-LambertW(exp(p))/(1+LambertW(exp(p)))+1

Error, invalid argument for sign, lcoeff or tcoeff

#it seems the following is a work around for the above case
#but why it is needed just here?
sign(op(1,expr))

-1

 

 

Download q1.mw

UPDATE

Thanks to comment below about using frontend. I never used this before except for now. It seems a very useful command and I think I will be using it a lot more from now on.

Just to clarify again what I want. I am just looking to see if there is a leading negative sign in front of an expression. I am not looking to find if the expression itself can be postive or negative when evaluated or anything more subtle or deep than that.

I simply want to check if there is literally a "-" in front of the maple expression. That is all.

Only issue left, is why Maple still gives Error, invalid argument for sign, lcoeff or tcoeff for the last example below? Here is the updated worksheet.

restart;

expr:=-sin(x)/ln(y)+1;
frontend(sign,[expr]);

-sin(x)/ln(y)+1

-1

expr:=sin(x)/ln(y)+1;
frontend(sign,[expr]);

sin(x)/ln(y)+1

1

expr:=-x;
frontend(sign,[expr]);

-x

-1

expr:=-LambertW(exp(p))+1;
frontend(print,[expr]);
frontend(sign,[expr]);

-LambertW(exp(p))+1

-O+1

-1

expr:=-LambertW(exp(p))/(1+LambertW(exp(p)))+1 ;
frontend(print,[expr]);
frontend(sign,[expr]);

-LambertW(exp(p))/(1+LambertW(exp(p)))+1

-O/(1+O)+1

Error, invalid argument for sign, lcoeff or tcoeff

 

 

Download q1_2.mw

Just a basic question, wanted to be clear.  When odeavisor returns a list of types (or classifications) of an ODE. This must mean the ODE can be of any one of these types?

For example, this ODE below, it says it is either homogeneous or rational or Abel or dAlembert.

I am asking because it can be much easier to solve an ODE if one knows if it is of one type vs. the other.

For example, for this one below, it is little easier to solve it if one sees it is Abel instead of dAelmbert. 

The hard part is knowing what type of ODE one is trying to solve and so it is important to pick the right/easier type to use.

Which brings another question: When Maple is given an ODE to solve, and it can be of number of types, how does it select which type to use to solve the ODE? Since the method to solve the ODE depends on the type of the ODE. (At least, when solving it by hand it does make a big difference).

Is there any detailed document that explains more how odeadvisor determines the type of the ODE? This is a very powerful and a useful command but I can't find in help any hints on how it determines the type of ODE.

It must use some general method/algorithm to approach this problem instead of trying to match each different ODE type one by one. right?  I tried to trace the code in the debugger, but I do not fully understand the code flow.

restart;

Typesetting:-Settings(typesetprime=true):

ode:=x^2*(4*x-3*y(x))*diff(y(x),x) = (6*x^2-3*x*y(x)+2*y(x)^2)*y(x)

x^2*(4*x-3*y(x))*(diff(y(x), x)) = (6*x^2-3*x*y(x)+2*y(x)^2)*y(x)

DEtools:-odeadvisor(ode)

[[_homogeneous, `class A`], _rational, [_Abel, `2nd type`, `class C`], _dAlembert]

DEtools:-odeadvisor(ode,['dAlembert']);
DEtools:-odeadvisor(ode,['Abel']);
DEtools:-odeadvisor(ode,['homogeneous']);

[_dAlembert]

[[_Abel, `2nd type`, `class C`]]

[[_homogeneous, `class A`]]

new_ode := diff(y(x),x)=convert(solve(ode,diff(y(x),x)),parfrac); # y'= the following below. So it is Abel indeed

diff(y(x), x) = -50/27-(2/3)*y(x)^2/x^2+(1/9)*y(x)/x-(200/27)*x/(-4*x+3*y(x))

#But to solve it as dAlembert, one need to rewrite it as y=x*g(y')+f(y') and it gets messy
#becuase one has to solve for y(x) first, and this will generate more than one ODE
ode:=convert(ode,D);
map(z-> y(x)=convert(z,diff),[solve(ode,y(x))])

x^2*(4*x-3*y(x))*(D(y))(x) = (6*x^2-3*x*y(x)+2*y(x)^2)*y(x)

[y(x) = ((1/2)*(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)-2*((1/2)*(diff(y(x), x))+3/4)/(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)+1/2)*x, y(x) = (-(1/4)*(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)+((1/2)*(diff(y(x), x))+3/4)/(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)+1/2+((1/2)*I)*3^(1/2)*((1/2)*(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)+2*((1/2)*(diff(y(x), x))+3/4)/(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)))*x, y(x) = (-(1/4)*(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)+((1/2)*(diff(y(x), x))+3/4)/(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)+1/2-((1/2)*I)*3^(1/2)*((1/2)*(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)+2*((1/2)*(diff(y(x), x))+3/4)/(5*(diff(y(x), x))-5+(8*(diff(y(x), x))^3+61*(diff(y(x), x))^2+4*(diff(y(x), x))+52)^(1/2))^(1/3)))*x]

 

 

Download q1.mw

 

 

 

From a book, it shows the following

Verified by hand the last result  above x^(2/3)+y^(2/3)-a^(2/3)=0 is correct. The input is always 2 equations in x and y as shown above, and there is always one constant C in both that needs to be eliminated to obtain a solution (one equation) that contains y,x and any other parameters, but without c.

have been trying to use eliminate command to do the same as above. I assume eliminate is the right command for this. But not able to get close to what the book shows above for final result. 

Does any one knows how obtain same result as above using Maple's eliminate?  (I can't follow the same steps as hand solution, since that would apply only to the above example. I need to use a generic approach). 

Sometimes it is hard to obtain same result using computer as one can do by "hand".

Here is some of my attempts

restart;

assume(x::real,y::real,a::real);
eq1:=x=-a/(1+c^2)^(3/2);
eq2:=y=a*c^3/(1+c^2)^(3/2);

x = -a/(c^2+1)^(3/2)

y = a*c^3/(c^2+1)^(3/2)

result:=eliminate([eq1,eq2],c);
result:=DEtools:-remove_RootOf(result[2,1]):
result:=DEtools:-remove_RootOf(result);
result:=simplify(result,power,symbolic);
result:=expand(result);

[{c = RootOf(_Z^2-RootOf(_Z^3*x+a)^2+1)}, {y*(RootOf(_Z^3*x+a)^2)^(3/2)-RootOf(_Z^2-RootOf(_Z^3*x+a)^2+1)*RootOf(_Z^3*x+a)^2*a+a*RootOf(_Z^2-RootOf(_Z^3*x+a)^2+1)}]

x*((a^2-y^2)*(a*y^2)^(1/3)*a*((a*y^2)^(2/3)+a*(a*y^2)^(1/3)+y^2))^(3/2)/(a*y^2*(a^2-y^2)^3)+a = 0

a*((y^(2/3)*a^(2/3)+a^(4/3)+y^(4/3))^(3/2)*x+(a^2-y^2)^(3/2))/(a^2-y^2)^(3/2) = 0

x*a*(y^(2/3)*a^(2/3)+a^(4/3)+y^(4/3))^(3/2)/(a^2-y^2)^(3/2)+a = 0

 

Download how_to_eliminate.mw

Notice: The reason I am asking the above, is becuase I was doing it this way: I first solve for from one equation, then use this result in the second equation (this is what one would do normally by hand). but this could result in many solutions and hard to know which to pick to match the book result. That is why I am thinking of using Elminate instead:

restart;

assume(x::real, y::real,a::real);
eq1:=x=-a/(1+c^2)^(3/2);
eq2:=y=a*c^3/(1+c^2)^(3/2);

x = -a/(c^2+1)^(3/2)

y = a*c^3/(c^2+1)^(3/2)

#brute force method
c_found:=Vector([solve(eq1,c)])

Vector(6, {(1) = sqrt((-a*x^2)^(2/3)-x^2)/x, (2) = -sqrt((-a*x^2)^(2/3)-x^2)/x, (3) = (1/2)*sqrt(2)*sqrt(I*sqrt(3)*(-a*x^2)^(2/3)-(-a*x^2)^(2/3)-2*x^2)/x, (4) = -(1/2)*sqrt(2)*sqrt(I*sqrt(3)*(-a*x^2)^(2/3)-(-a*x^2)^(2/3)-2*x^2)/x, (5) = (1/2)*sqrt(-(2*I)*sqrt(3)*(-a*x^2)^(2/3)-2*(-a*x^2)^(2/3)-4*x^2)/x, (6) = -(1/2)*sqrt(-(2*I)*sqrt(3)*(-a*x^2)^(2/3)-2*(-a*x^2)^(2/3)-4*x^2)/x})

map(x->simplify(subs(c=x,eq2),symbolic),c_found)

Vector(6, {(1) = y = -(1/4)*sqrt(2)*(I*a^(2/3)*sqrt(3)-a^(2/3)-2*x^(2/3))^(3/2), (2) = y = (1/4)*sqrt(2)*(I*a^(2/3)*sqrt(3)-a^(2/3)-2*x^(2/3))^(3/2), (3) = y = -((1/4)*I)*sqrt(2)*(I*a^(2/3)*sqrt(3)+a^(2/3)+2*x^(2/3))^(3/2), (4) = y = ((1/4)*I)*sqrt(2)*(I*a^(2/3)*sqrt(3)+a^(2/3)+2*x^(2/3))^(3/2), (5) = y = -(a^(2/3)-x^(2/3))^(3/2), (6) = y = (a^(2/3)-x^(2/3))^(3/2)})

 

 

Looking at result above, I think I can safely eliminate all y solutions with complex number I in them. This leaves the last two listed above (real y). Which is a little better than before.

Download how_to_eliminate_brute_force.mw

 

 

I do not understand why Maple sometimes shows singular solution to Clairaut ODE and sometimes not.

Clairaut ODE has the form y(x) = x y'(x) + G(x, y')

In the following ODE when I ask Maple to dsolve it as is, it does give singular solution. Next, when solving explicity for y(x) first, which will generate 2 ODE's, each is Clairaut ODE, then ask Maple to dsolve each, now Maple no longer gives the singular solution. But when I solve each one of these ODE's, I see that there is the singular solution there. It must be there, since this is Clairaut ODE and it has singular solution.

When I do PDEtools:-casesplit on each of the two ODE's generated by solving for y(x) first, I see the singular solution there.

The question is, why Maple dsolve does not show the singular solution in the second case? And how to make it show it? Or did I do something wrong?

restart;

Typesetting:-Settings(typesetprime=true):

ode:=x^2*diff(y(x),x)^2-(1+2*x*y(x))*diff(y(x),x)+1+y(x)^2 = 0;

x^2*(diff(y(x), x))^2-(1+2*x*y(x))*(diff(y(x), x))+1+y(x)^2 = 0

DEtools:-odeadvisor(ode)

[[_1st_order, _with_linear_symmetries], _rational, _Clairaut]

Vector([dsolve(ode,y(x))]); #now it shows singular solution (first one below)

Vector(3, {(1) = y(x) = (1/4)*(4*x^2-1)/x, (2) = y(x) = _C1*x-sqrt(_C1-1), (3) = y(x) = _C1*x+sqrt(_C1-1)})

PDEtools:-casesplit(ode)

`casesplit/ans`([(diff(y(x), x))^2 = (2*y(x)*(diff(y(x), x))*x+diff(y(x), x)-y(x)^2-1)/x^2], [2*(diff(y(x), x))*x^2-2*x*y(x)-1 <> 0]), `casesplit/ans`([y(x) = (1/4)*(4*x^2-1)/x], [])

ode:=convert(ode,D): #solve for y(x) first, this will generate 2 ODE's
sol:=[solve(ode,y(x))]:
odes:=Vector(map(z->y(x)=z,convert(sol,diff)))

Vector(2, {(1) = y(x) = (diff(y(x), x))*x+sqrt(diff(y(x), x)-1), (2) = y(x) = (diff(y(x), x))*x-sqrt(diff(y(x), x)-1)})

DEtools:-odeadvisor(odes[1]);
DEtools:-odeadvisor(odes[2]);

[[_1st_order, _with_linear_symmetries], _rational, _Clairaut]

[[_1st_order, _with_linear_symmetries], _rational, _Clairaut]

dsolve(odes[1],y(x)); #where is singular solution?

y(x) = _C1*x+(_C1-1)^(1/2)

dsolve(odes[2],y(x)); #where is singular solution?

y(x) = _C1*x-(_C1-1)^(1/2)

PDEtools:-casesplit(odes[1])

`casesplit/ans`([diff(y(x), x)-1 = (-(diff(y(x), x)-1)^(1/2)+y(x)-x)/x, diff(y(x), x) = (-(diff(y(x), x)-1)^(1/2)+y(x))/x], [1+2*x*(diff(y(x), x)-1)^(1/2) <> 0]), `casesplit/ans`([y(x) = (1/4)*(4*x^2-1)/x], [])

PDEtools:-casesplit(odes[2])

`casesplit/ans`([diff(y(x), x)-1 = ((diff(y(x), x)-1)^(1/2)+y(x)-x)/x, diff(y(x), x) = ((diff(y(x), x)-1)^(1/2)+y(x))/x], [2*x*(diff(y(x), x)-1)^(1/2)-1 <> 0]), `casesplit/ans`([y(x) = (1/4)*(4*x^2-1)/x], [])

 

 

Download missing_singular.mw

To help decide the type of ODE, I need a function which moves all derivatives to lhs and everything else to the rhs of the ODE. This way I can more easily analyze the ODE.

The ode will be only first order. Any term which contains  (y')^n, is to be moved to the lhs. Rest to rhs. Couple of examples will help illustrate the problem. This is done in code only, without looking at the screen. The dependent variable is always y and the independent variable is x.  So I need to turn the ODE to the form 

                    G(y',y'^2,y'^3,.....,y'^n)  = F(x,y)

I can find all derivatives in the ODE using

indets['flat'](ode,{`^`('identical'(diff(y(x),x)),'algebraic'),'identical'(diff(y(x),x))})

But not sure how this will help me do what I want. isolate does not help, since it only takes one term at a time. Collect also did not help for same reason.  If the ODE contains only ONE derivative, then it is easy to do. But the question is about how to do it for ODE which contains more than y' term of different powers as the examples below show.

What methods to do this in Maple? I looked at DEtools but so far did not see anything.

Example 1

 

restart;
ode:=3*diff(y(x),x)^2+diff(y(x),x)^3+sin(x)+y(x)=x*y(x)+x*diff(y(x),x);

3*(diff(y(x), x))^2+(diff(y(x), x))^3+sin(x)+y(x) = x*y(x)+x*(diff(y(x), x))

indets['flat'](ode,{`^`('identical'(diff(y(x),x)),'algebraic'),'identical'(diff(y(x),x))})

{(diff(y(x), x))^2, (diff(y(x), x))^3, diff(y(x), x)}

ode_wanted:= 3*diff(y(x),x)^2+diff(y(x),x)^3-x*diff(y(x),x)=-sin(x)-y(x)+x*y(x)

3*(diff(y(x), x))^2+(diff(y(x), x))^3-x*(diff(y(x), x)) = -sin(x)-y(x)+x*y(x)

Example 2

 

restart;
ode:=3*diff(y(x),x)^2+diff(y(x),x)=x*diff(y(x),x)+5;

3*(diff(y(x), x))^2+diff(y(x), x) = x*(diff(y(x), x))+5

indets['flat'](ode,{`^`('identical'(diff(y(x),x)),'algebraic'),'identical'(diff(y(x),x))})

{(diff(y(x), x))^2, diff(y(x), x)}

ode_wanted:= 3*diff(y(x),x)^2+diff(y(x),x)-x*diff(y(x),x)=5

3*(diff(y(x), x))^2+diff(y(x), x)-x*(diff(y(x), x)) = 5

 

 

Download lhs_rhs.mw

 

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