nm

3806 Reputation

17 Badges

8 years, 19 days

MaplePrimes Activity


These are questions asked by nm

sqrt(4) gives 2 in CAS systems, since the principal root is returned by default. 

Is there an option to have Maple return all roots? Which in this case 2,-2?

I'll explain the context why I need this.

When I solve an ODE, I get a solution that I need to solve for constant of integration C from initial conditions. For an example assume the ODE becomes, after replacing initial condition the following  eq:=4^(1/2) = -2+_C1;

So now when solving for _C1  in maple and then calling simplify, gives one solution which _C1=4 (case root=2) which when replaced back into the general solution gives the particular solution.

But this means the second solution is lost, which is when _C1=0  (case root=-2) which could have been obtained from the non-principal root of 4^(1/2)

eq:=4^(1/2) = -2+_C;
solve(eq,_C);

gives 

And I would like to get {4,0} instead.

In practice, this becomes important.

Here is an actual ODE, which should have 2 solutions. Mathematica gives both solutions, and Maple gives one solution.  This is due to the above.

ode:=diff(y(x),x)-y(x)=x*y(x)^(1/2);
ic:=y(0)=4;
dsolve([ode,ic])

In Mathematica

ode=y'[x]-y[x]==x*y[x]^(1/2);
ic={y[0]==4};
sol=DSolve[{ode,ic},y[x],x]

The second solution above came from when constant of integration is zero. The first solution is the one Maple  gave (when expanded).

When I worked the solution by hand, I tracked this to issue with sqrt(4) giving 2 and not +2,-2 when doing solve() to solve for C at the end.

I could ofcourse leave C=sqrt(4)  and not call simplify  on it  and that works.

But I thought to ask here to see if there is some option in Maple, so that when it sees (n)^m to return all m roots when calling solve() and not just the principal one. Even for m=2. 

I looked at root and tried allsolutions=true but they did not help. Looked at solve/details and did not spot something. I tried only few of the options there, as there are so many.

Any suggestions what to try?

 

I can't understand why select(has,3*C,x) returns 1  and select(has,3+C,x) returns 0

I was expecting to get NULL or {}. But when doing select(has,[3*C],x) and select(has,[3+C],x)  now both return [ ] as expected

Where did 1 and 0 come from in the above examples? I looked at help page, but do not see it.

restart;
select(has,3*C,x)

restart;
select(has,3+C,x)

or the same:

restart;
select(z->has(z,x),3*C);
select(z->has(z,x),3+C)

 

The select function selects the operands of the expression e which satisfy
the Boolean-valued procedure f, and creates a new object of the same type
as e. Those operands for which f does not return true are discarded in the
newly created object.

 

The above is the same as if one typed

select(x->false,3+C);
       0

select(x->false,3*C);
       1

 

I am trying to learn how do somethings without using pattern matching and it is a struggle so far for me.

For an example, now I want to ask Maple to tell me if C[1] (which is a constant) exist in expression, as long as C[1] does not occur as argument to exp(....)

I'll explain why I want to do this and show small example and show how I ended solving it and ask if there is better way.

Given this expression (this can be result of dsolve for example. Made up here)

I just need to determine if the expression has C[1] anywhere, which is NOT an argument to exp(). In the above example, there is one.

The reason I want to find this, is that this is the constant of integration for first order ODE, and I want to repalce exp(C[1]) by constant C[1], but as long as there is no C[1] allready anywhere in expression on its, otherwise I need to introduce new constant C[2], which I do not want to do (since first order, should have only one constant of integration) and in this case will leave the expression as is and not try to simplify it.

But indets tells one that C[1] is there, not where. This is what I tried

restart;
expr:=1/exp(z)*arcsinh(x*exp(C[1]))+x*C[1]*sin(exp(x))+3*exp(C[1]*y)*sqrt(sin(exp(3*C[1])));
indets(expr, specfunc(exp));

Now I can find if C[1] is argument to exp(....) from the above or not by more processing. (using applyrule or subsindets, etc...)

But first I still need to to determine if there is C[1] that exist anywhere else, as long it is not inside exp(.....).  If I do 

indets(expr, C[1]);

But this does not tell me the information I want. It just says expression has C[1] somewhere.

I looked at evalindets and looked at applyrule and do not see how to use these to do what I want.

Basically I want to tell Maple this

     indets(expr,C[1], conditional( C[1] is not anywhere inside exp(.....) ))

I can solve this using pattern matching. But I fnd Maple pattern matching awkaward to use sometimes and trying to learn how to do things without it.

So this is how I ended solving it. I replace all the C[1] inside exp(....) with ZZZ. Then use indets again to check if C[1] still there or not. This tells me what I want. 

restart;
expr:=1/exp(z)*arcsinh(x*exp(C[1]))+x*C[1]*sin(exp(x))+3*exp(C[1]*y)*sqrt(sin(exp(3*C[1])));
new_expr:=subsindets(expr, specfunc(exp), ()-> ZZZ);
if indets(new_expr, C[1])<>{} then
   print("C[1] exist outside exp()");
else
   print("C[1] does not exist outside exp()");
fi;

"C[1] exist outside exp()"

And

restart;
expr:=1/exp(z)*arcsinh(x*exp(C[1]))+x*sin(exp(x))+3*exp(C[1]*y)*sqrt(sin(exp(3*C[1])));
new_expr:=subsindets(expr, specfunc(exp), ()-> ZZZ);
if indets(new_expr, C[1])<>{} then
   print("C[1] exist outside exp()");
else
   print("C[1] does not exist outside exp()");
fi;

"C[1] does not exist outside exp()"

is there a better way to do this?

Given some expression, I want to replace each exp(.....) in it with something else.

This is what I currently do. First I find all the exp() terms, then using a loop and use subs  like this

restart;
expr:=1/exp(z)*arcsinh(x*exp(C[1]))+x*sin(exp(x))+3*exp(C[1]*y)*sqrt(sin(exp(3*h)));

#find all exp terms
s:=select(x->has(x,exp),indets(expr));
s:=select(x->op(0,x)='exp',s)

Now, lets says I want to replace each with Z

I tried to use but that did not work.

So now I am doing this

for item in s do
    expr:=subs(item=Z,expr);
od:
expr

is it possible do this without a loop? could not do it using ~

With map, I can do this map(x->subs(x=Z,expr),s) but this does not replace it inside expr where I want. 

Assignment is not allowed inside the above so I can not do  this map(x->expr:=subs(x=Z,expr),s)

And if I do expr:=map(x->subs(x=Z,expr),s)  it does not work either. it gives

 

How to do the replacement without using a do loop? 

 

 

 

This is the Maple code

restart;
result:=int(1/tanh(u),u)

simplify(result,size) ;
simplify(result,symbolic);
simplify(result,ln);
simplify(result,trig);

Any suggestions?

 

 

First 6 7 8 9 10 11 12 Last Page 8 of 86