nm

11353 Reputation

20 Badges

13 years, 12 days

MaplePrimes Activity


These are replies submitted by nm

@Kitonum 

Thank for the suggestion of possible explanation. But this can not be the correct reason for the error.

I am well aware that one can not have diff(y(x),x) in the equation, and also solve for y(x). This is why I changed the ODE to D(y)(x) before calling solve.

I have been using this same code for over a year now and run my program over many thousands of ODE's, hundreds of times by now, and never saw such an error. This is the first time I see this error.

You could try it yourself. 

restart;
interface(warnlevel=4):
kernelopts('assertlevel'=2):
eq:=exp(x)*sin(y(x))-3*x^2+(exp(x)*cos(y(x))+(1/3)/y(x))*(D(y))(x) = 0;
timelimit(30,solve(eq,y(x)));

No errror. If you like me to post 4,000 more examples I have that does the same thing and give no error, I will be happy to, but one can pick any random ODE and do the same thing, i.e. solve for y(x) after converting the diff to D, and it works.

restart;
interface(warnlevel=4):
kernelopts('assertlevel'=2):
ode:=diff(y(x),x)+y(x)-x=0;
eq:=convert(ode,D);
timelimit(30,solve(eq,y(x)));

If your theory is correct, then could you please explain why it works in the almost 4,000 other ODE's I have in my collection, and been running it for over a year with no error, but it failed on this specific equation I just added last night?

 

This is what I get on 2020.2

Are you sure it is (sin(t)^2)^exp(t) and not (sin(t)^2)*exp(t) ?

Need to use numerical integration. But Maple have hard time with numerical integration when x starts at some points vs. others. 

I tried it in Mathematica, and it can do it for all points (numerically).

May be there are other options to make Maple integrate this numerically. I only tried the basic int command with numeric option. Here is Mathematica result (do not know if it accurate or not)

 

It doesn't seem that Maple has a built-in procedure to construct the syntactic graph of a mathematical expression.
But maybe I'm wrong?

I think you are correct. This is build-in Mathematica. It is called TreeForm

Here is the result applied to your example

It will be useful to have this in Maple as well. Maple's  dismantle is not the same, and it is more like Mathematica's other command called FullForm

@acer 

 Are they the same?

No. The result from Rubi was not automatically simplified optimally. FullSimplify was needed to simplify it more.

@Parham2016 

"there was not the function of InverseJacobiAM, but your second solution did include it."

This is how Maple translated the Mathematica output. 

But if you say you have Mathematica itself allready, why not run Rubi there and see the solution I posted for yourself? You can install Rubi from the here

 

Any way, please find Rubi integrate output below. I just asked Maple to translate it.

Get["Rubi`"]; 
integrand = ((k/2)*x^2 + x + c)/Sqrt[lambda^2*(1 + k*x)^4 - ((k/2)*x^2 + x + c)^2]; 
sol = FullSimplify[Int[integrand, x]]

it gives

-((Sqrt[-4*c^2 + 4*lambda^2*(1 + k*x)^4 - 4*c*x*(2 + k*x) - x^2*(2 + k*x)^2]*(2*Sqrt[-1 + 2*c*k]*(1 - 4*k^2*lambda^2)^(1/4)*(1 + k*x)*
      Sqrt[(k^2*(4*c^2 - 4*lambda^2*(1 + k*x)^4 + 4*c*x*(2 + k*x) + x^2*(2 + k*x)^2))/(-1 + 2*c*k + Sqrt[1 - 4*k^2*lambda^2] + 
          k*Sqrt[1 - 4*k^2*lambda^2]*x*(2 + k*x))^2] + (2 - 4*c*k)*EllipticE[2*ArcTan[((1 - 4*k^2*lambda^2)^(1/4)*(1 + k*x))/Sqrt[-1 + 2*c*k]], 
       (1/2)*(1 - 1/Sqrt[1 - 4*k^2*lambda^2])] + (-1 + 2*c*k)*(1 + Sqrt[1 - 4*k^2*lambda^2])*
      EllipticF[2*ArcTan[((1 - 4*k^2*lambda^2)^(1/4)*(1 + k*x))/Sqrt[-1 + 2*c*k]], (1/2)*(1 - 1/Sqrt[1 - 4*k^2*lambda^2])]))/
   (2*Sqrt[-1 + 2*c*k]*(1 - 4*k^2*lambda^2)^(3/4)*(-1 + 2*c*k + Sqrt[1 - 4*k^2*lambda^2] + k*Sqrt[1 - 4*k^2*lambda^2]*x*(2 + k*x))*
    Sqrt[(k^2*(4*c^2 - 4*lambda^2*(1 + k*x)^4 + 4*c*x*(2 + k*x) + x^2*(2 + k*x)^2))/
      (-1 + 2*c*k + Sqrt[1 - 4*k^2*lambda^2] + k*Sqrt[1 - 4*k^2*lambda^2]*x*(2 + k*x))^2]))

To translate the above to Maple, copy it to your Maplework sheet, and put ` and ` on each side of the expression and then call MmaTranslator on it as shown in the screen shot above. Maple will translate the above Mathematica expression to Maple syntax.

 

@lcz 

Yes, in Mathematica one can do this

ls[[1 ;; -1 ;; 2]]

But same thing is not possible in Maple. At least I could not figure how to do it. One can only take a slice, with increment of one, as in

ls[1..nops(ls)]

But not using different increments, say by 2

ls[1..nops(ls),2]

That is why seq is needed.

 

@lcz 

At the beginning I thought there would be a simple and fast function. Just like mathematica. 

The first Mathematica code from the link you have

Table[a[[i]], {i, 1, le, 2}]

is really the same as the Maple code 

seq(ls[i],i=1..nops(ls),2)

In Mathematica, Table[] is like seq() in Maple.  Notice, you asked for odd and even. The question you linked to asked for just odd. So may be that why the Maple code I posted looked a little longer.

@vv 

"It seems that there is an easy method."

yes. That is easier. This is the method that I wrote down yesterday below.  

@mmcdara 

Thanks for the idea. But it does not work for all case. For example given this

It does not do it:

restart:
expr:=y^2+y^3*sin(x)+3*x*y^(7/2);
convert(expr, horner, y)

But when doing this by hand, we see it can be factored as

proof:

should_be:=y^2*(1+y*sin(x)+3*x*y^(3/2));
expand( should_be )

@Parham2016 

Rubi is a Mathematica package. There is no port for it for Maple at this time. So you need Mathematica to run the above.

Here is the above result in Maple syntax

-sqrt(-4*c^2 + 4*lambda^2*(k*x + 1)^4 - 4*c*x*(k*x + 2) - x^2*(k*x + 2)^2)*(2*sqrt(2*c*k - 1)*(-4*k^2*lambda^2 + 1)^(1/4)*(k*x + 1)*sqrt(k^2*(4*c^2 - 4*lambda^2*(k*x + 1)^4 + 4*c*x*(k*x + 2) + x^2*(k*x + 2)^2)/(-1 + 2*c*k + sqrt(-4*k^2*lambda^2 + 1) + k*sqrt(-4*k^2*lambda^2 + 1)*x*(k*x + 2))^2) + (-4*c*k + 2)*EllipticE(sin(2*arctan((-4*k^2*lambda^2 + 1)^(1/4)*(k*x + 1)/sqrt(2*c*k - 1))), sqrt(1/2 - 1/(2*sqrt(-4*k^2*lambda^2 + 1)))) + (2*c*k - 1)*(1 + sqrt(-4*k^2*lambda^2 + 1))*InverseJacobiAM(2*arctan((-4*k^2*lambda^2 + 1)^(1/4)*(k*x + 1)/sqrt(2*c*k - 1)), sqrt(1/2 - 1/(2*sqrt(-4*k^2*lambda^2 + 1)))))/(2*sqrt(2*c*k - 1)*(-4*k^2*lambda^2 + 1)^(3/4)*(-1 + 2*c*k + sqrt(-4*k^2*lambda^2 + 1) + k*sqrt(-4*k^2*lambda^2 + 1)*x*(k*x + 2))*sqrt(k^2*(4*c^2 - 4*lambda^2*(k*x + 1)^4 + 4*c*x*(k*x + 2) + x^2*(k*x + 2)^2)/(-1 + 2*c*k + sqrt(-4*k^2*lambda^2 + 1) + k*sqrt(-4*k^2*lambda^2 + 1)*x*(k*x + 2))^2))

Rubi gives simplest solution.

 

@Carl Love 

Your first one worked

     foo:= proc(..., {ic::`=`:= ()=()}) ....

I will use this. Thanks. Its default  type is equation, so now I can pass it, and it is still type equation.

But your second choice is not type equation. Maple says it is type expression sequence 

Thanks. Will use the first one you showed. It works for what I need.

restart;
foo:=proc(n::integer, {ic::{`=`, identical()}:= ()})
    print(whattype(ic));
    print(type(ic,`=`));
end proc;

foo(3);

@Carl Love 

But now I am able to call the top function with something which is not an equation and it passes through. WHich I do not want. I wanted Maple to catch this. May be I should give a new example of the problem. Instead of using [] as default value, I'll make a NULL.  

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc(n::integer,{ic::`=`:=NULL})      
   post_process(n+1,':-ic'=ic);
end proc;

post_process:=proc(n::integer,{ic::`=`:=NULL})      
    print("in postprocess, n=",n, "ic=",ic);
end proc;

Now foo can only be called, with ic of type equation. If not present, it will get NULL.   And the problem is now, when foo calls post_process, it will fail, since NULL is not an equation. 

foo(3)
Error, (in foo) invalid input: post_process expects value for keyword parameter ic to be of type `=`, but received NULL

if I do what you suggested, then error goes away, but also caller can now call foo() with [], which is not equation, and maple no longer detect it:

restart;
foo:=proc(n::integer,{ic::{`=`, {list, set}(`=`)}:=[]})
   post_process(n+1,':-ic'=ic);
end proc;

post_process:=proc(n::integer,{ic::{`=`, {list, set}(`=`)}:=[]})
    print("in postprocess, n=",n, "ic=",ic);
end proc;

foo(3,':-ic'=[]); #no error from Maple. But I only want to pass `=` for ic.

The problem is that Maple wants default value for keyword. But keyword argument type I want is  equation.

I do not know what default value to give it, which is also of type equation. That is why I had [] there. And now have NULL.

May be we need a NULL EQUATION type !

@Carl Love 

Ok, thanks. I did not know this. This takes care of the first issue. I still have the second issue to figure out. I.e.

restart;
foo:=proc(n::integer,{ic::`=`:=[]})   
   post_process(n+1,':-ic'=ic);
end proc;

post_process:=proc(n::integer,{ic::`=`:= []})
    print("in postprocess, n=",n, "ic=",ic);
end proc;

foo(3,':-ic'=(y(0)=5)); #now works.

foo(3)  #error due to default value 

Currently as I said, I take care of this, by checking for nargs, which I'd like to avoid doing.

First 43 44 45 46 47 48 49 Last Page 45 of 91