nm

8552 Reputation

19 Badges

12 years, 355 days

MaplePrimes Activity


These are questions asked by nm

Maple gives solution to equation as RootOf when there is no explicit solution

restart;
eq:=x*sin(x*y)+y+1=0;
sol:=solve(eq,y)

The _Z above, is the variable we wanted to solve for, which is in this example. My question is, why did not Maple give the solution as

sol2:=RootOf(x*sin(_Z*x)+_Z+1)

Which is a little simpler looking. Is the above not the same as what Maple gives?  I just replace by _Z 

Digits:=100;
plot(evalf(sol-sol2),x=0..Pi)

sometimes Maple's solution for an ode is not valid for all x. When I run odetest on the solution, it is not zero.

For the case when the output of odetest contains one csgn(), I am trying to determine if odetest result will become zero, when csgn is +1  or -1. If so, then next look into the argument of csgn and solve for x under this condition and hence find the range of x when the solution is valid.

I wrote the following to do this and check the idea.

I'd like to ask if the Maple experts here can suggest improvement or if there a better way to do this.

The code below works if there is only instance of csgn() in the output of odetest. Which covers almost all the cases I saw so far.

The code first checks if csgn is present in the output of odetest. If so, it then uses indents to pick up the function csgn out. Then uses op to pick its argument. Then uses solve with inquality to find when the argument is either positive or negative. This results in the range of x needed to make odetest zero.

This is just a quick prototype to test the idea. This not the final code I will be using as that will include more checks and be more robust. 

restart;
ode :=diff(y(x),x)=2*(x*sqrt(y(x))-1)*y(x):
ic  :=y(0)=1:
sol :=dsolve([ode,ic]):
res :=odetest(sol,ode);

So we see odetest did not give zero.  The issue is that I can't just do 

solve(res=0,x)

It does not work.  So that is why I had to look inside as follows:

The goal is to check if when csgn is either +1 or -1, if it will then become zero.

And if so, then also find the range of x which will caused this.  In the above, we see that when 1/(x+1) is +1, then odetest result  will become zero. This means x has to be larger than -1.

Note that this is all done in code, without being able to look at the screen and then decide what to do

if res<>0 then
    if has(res,csgn) then
        if simplify( subsindets(res,csgn(anything),f->1)) = 0 then      
            print("the odetest becomes zero when csgn is POSITIVE");
            Z:=indets(res,specfunc(csgn));
            the_args:=map(x->op(x),Z);
            print("Now solve ",the_args," for x, when the expression is POSTIVE");
            for tmp in the_args do
                result:=solve(tmp>0,x);
                print("the solution is valid for x>", op([1,1],result));
            od;
        else
            if simplify( subsindets(res,csgn(anything),f->-1)) = 0 then      
                print("the odetest becomes zero when csgn is POSITIVE");
                indets(res,specfunc(csgn));
                the_args:=map(x->op(x),Z);
                print("Now solve ",the_args," for x, when the expression is negative");
                for tmp in the_args do
                    result:=solve(tmp<0,x);
                    print("the solution is valid for x<", op([1,1],result));
                od;
            else
                print("give up. Tried when csgn is positive or negative");
            fi;
        fi;
    fi;
fi;

If there is more than one csgn function in the odetest result, it will become much more complicated, since one have to check all combinations to find under which combination odetest will become zero. So for now, I am just doing this only for one case of csgn present.

 

I found small problem in Latex(). When putting solution of ODE inside a Vector, Latex() fails to convert and returns empty vector.

restart;
sol:=[dsolve(diff(diff(y(x),x),x)*y(x) = 1,y(x))];
sol:=convert(sol,Vector);

And now

Latex(sol)


               \left[\begin{array}{c} \\ \end{array}\right]

Empty array. But if not in a Vector, it works

restart;
sol:=[dsolve(diff(diff(y(x),x),x)*y(x) = 1,y(x))];
Latex(sol)

# no problem here ====>

\left[
{\textcolor{gray}{\int}}_{}^{y \! \left(x \right)}\frac{1}{\sqrt{2 \ln \! \left(\mathit{\_a} \right)-2 \mathit{\_C1}}}\textcolor{gray}{d}\mathit{\_a} -x -\mathit{\_C2}
 = 0, 
{\textcolor{gray}{\int}}_{}^{y \! \left(x \right)}-\frac{1}{\sqrt{2 \ln \! \left(\mathit{\_a} \right)-2 \mathit{\_C1}}}\textcolor{gray}{d}\mathit{\_a} -x -\mathit{\_C2}
 = 0\right]

 

This seems to happen on some solutions (may be those with Int because in this other example, it works with Vector):

restart;
sol:=[dsolve(diff(diff(y(x),x),x)*y(x)^2 = 0)];
sol:=convert(sol,Vector);

And now

Latex(sol)

#now it works ===>

\left[\begin{array}{c}y \! \left(x \right)=0 \\y \! \left(x \right)=\mathit{\_C1} x +\mathit{\_C2}  \end{array}\right]

I am using Maple 2020.2 with Physics 897

Edit 1/2/2021

I found another strange problem with Latex conversion related to Vector. If the first entry is y(x)=0 in the vector, then it keeps this, but throws away the rest of the entries in the Vector.

This might be related to the same bug. Not sure. Here is an example

restart;
ode:=(2*cot(x)*diff(y(x),x)*y(x)+diff(y(x),x)^2-y(x)^2 = 0,singsol=all);
sol:=convert([dsolve(ode)],Vector)

Now watch what happens when converting sol to Latex

Latex(sol)

    \left[\begin{array}{c}y \! \left(x \right)=0 \\ \\ \end{array}\right]

Only reason I use Vector() is to display in Latex many solutions on top of each others, so easier to see instead of as a list() where they are all on one line, which might not fit the page.

I need to find an alternative to using Vector to do this. 

What is the letter O doing inside this pde solution by Maple 2020.2 and what does it mean? There is no O in the PDE itself and it is not a name of a mathematical special function 

restart;
interface(version);
pde :=  diff(w(x,y),x)+ (a*x^2*y+b*y^3)*diff(w(x,y),y) = 0;
sol:=pdsolve(pde,w(x,y));

 

lprint(sol)

w(x,y) = _F1(1/9*(2*2^(2/3)*3^(5/6)*b*x*O*y^2-3*2^(2/3)*3^(1/3)*b*x*GAMMA(1/3,-\
2/3*x^3*a)*GAMMA(2/3)*y^2+9*O*GAMMA(2/3)*exp(2/3*x^3*a))/O/GAMMA(2/3)/y^2)

 

Please see this example. This Latex generated gives Latex compile error.

restart;
Latex:-Settings(UseImaginaryUnit=i,
      UseColor = false,
      powersoftrigonometricfunctions= mixed, ## computernotation,
      leavespaceafterfunctionname = true,
      cacheresults = false,
      spaceaftersqrt = true  
);

L:=3;
c:=4;
h:=1/10;
b:=Pi*c/L;
f:=piecewise(0<x and x<L/3,3*h/L*x,L/3<x and x<L,h);
pde := diff(u(x,t),t$2) + b*diff(u(x,t),t) = c^2*diff(u(x,t),x$2);
bc  := u(0,t)=0,D[1](u)(L,t)=0;
ic  := D[2](u)(x,0)=0,u(x,0)=f;
sol:=pdsolve([pde,bc,ic],u(x,t));

The Latex generated does not compile:

Latex(sol)


u \left(x , t\right) = 
\Mapleoverset{\infty}{\Mapleunderset{n =0}{\sum}}\left\{\begin{array}{44}\frac{4 \,{\mathrm e}^{-\frac{2 t \pi}{3}} \left(t \pi +\frac{3}{2}\right) \sin \left(\frac{\pi  x}{6}\right)}{5 \pi^{2}} & n =0 \\\frac{3 \sin \left(\frac{\left(1+2 n \right) \pi  x}{6}\right) \left(\sqrt{3}\, \sin \left(\frac{\pi  n}{3}\right)+\cos \left(\frac{\pi  n}{3}\right)\right) \left(\left(2 \sqrt{n}\, \sqrt{n +1}+i\right) {\mathrm e}^{\frac{2 i \pi  \left(-2 \sqrt{n}\, \sqrt{n +1}+i\right) t}{3}}-{\mathrm e}^{\frac{2 i \pi  \left(2 \sqrt{n}\, \sqrt{n +1}+i\right) t}{3}} \left(-2 \sqrt{n}\, \sqrt{n +1}+i\right)\right)}{10 \sqrt{n}\, \sqrt{n +1}\, \pi^{2} \left(1+2 n \right)^{2}} & \mathit{otherwise}  \end{array}\right.

Gives

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{maplestd2e}  

\begin{document}
\[
u \left(x , t\right) = 
\Mapleoverset{\infty}{\Mapleunderset{n =0}{\sum}}\left\{\begin{array}{44}\frac{4 \,{\mathrm e}^{-\frac{2 t \pi}{3}} 
   \left(t \pi +\frac{3}{2}\right) \sin \left(\frac{\pi  x}{6}\right)}{5 \pi^{2}} 
    & n =0 \\\frac{3 \sin \left(\frac{\left(1+2 n \right) \pi  x}{6}\right) 
    \left(\sqrt{3}\, \sin \left(\frac{\pi  n}{3}\right)+\cos \left(\frac{\pi  n}{3}\right)\right) 
    \left(\left(2 \sqrt{n}\, \sqrt{n +1}+i\right) {\mathrm e}^{\frac{2 i \pi  \left(-2 \sqrt{n}\, 
    \sqrt{n +1}+i\right) t}{3}}-{\mathrm e}^{\frac{2 i \pi  \left(2 \sqrt{n}\, \sqrt{n +1}+i\right) t}{3}} 
    \left(-2 \sqrt{n}\, \sqrt{n +1}+i\right)\right)}{10 \sqrt{n}\, \sqrt{n +1}\, \pi^{2} \left(1+2 n \right)^{2}} 
    & \mathit{otherwise}  \end{array}\right.
\]

\end{document}

This, using latest TeXLive on Linux, gives  Illegal character in array arg.

lualatex foo5.tex
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020)
 restricted system commands enabled.
(./foo5.tex
LaTeX2e <2020-10-01> patch level 2


 L3 programming layer <2020-12-07> xparse <2020-03-03> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size11.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/mnt/g/public_html/styles/maplestd2e.sty
Package: maple2e 2005/03/17 v1.16
Defining Maple Utility Macros
(/mnt/g/public_html/styles/mapleenv.def)
Defining Maple Plot Environemnts
 ...Defaults to "dvips" Driver
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/epsfig.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphics.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/trig.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics-cfg/graphics.cfg) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics-def/dvips.def))))
Defining Automatic Style Generation Macros
Defining Maple Spreadsheet Environments
Maple Spreadsheet and Table Support
) (/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-luatex.def) (./foo5.aux) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd)

! LaTeX Error: Illegal character in array arg.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...haracter\or Missing @-exp\or Missing p-arg\fi \space in array arg.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help\@err@

l.8 \Mapleoverset{\infty}{\Mapleunderset{n =0}{\sum}}\left\{\begin{array}{44}
                                                                           \frac{4 \,{\mathrm e}^{-\frac{2 t \pi}{3}}
?

fyi. No errors are generated from the old latex() command.

The following is another example, with the same Latex error. 

restart;
Latex:-Settings(UseImaginaryUnit=i,
      UseColor = false,
      powersoftrigonometricfunctions= mixed, ## computernotation,
      leavespaceafterfunctionname = true,
      cacheresults = false,
      spaceaftersqrt = true  
);

c:=3;
f:=piecewise(4<x and x<5,1,true,0);
pde := diff(u(x, t), t$2) = c^2*(diff(u(x, t), x$2));
bc  := eval( diff(u(x,t),x),x=0)=0;
ic  := u(x,0)=f(x),eval(diff(u(x,t),t),t=0)=0;
sol:=pdsolve([pde, bc,ic],u(x,t)) assuming x>0,t>0;

Latex(sol);  #gives Latex that do not compile

Maple 2020.2, with Physics 897

First 63 64 65 66 67 68 69 Last Page 65 of 164