nm

11458 Reputation

20 Badges

13 years, 77 days

MaplePrimes Activity


These are answers submitted by nm

see Improving-Phaseplot-For-System-Of-Odes for reference. There is no function which gives exactly as StreamPlot in Maple, but DEtools:-DEplot gets close. The difference is that in Mathematica the arrows follow each others along one stream, but in Maple they are disconnected. i.e. where one arrow ends, is not same location where the next arrow starts.

This makes Mathematica's output a little more pleasing to look at than Maple's IMNSHO.

ode=y'[x]==y[x]-x
f[x_,y_]:=y-x
p1=StreamPlot[{1,f[x,y]},{x,-5,6},{y,-4,3},
           Frame->False,Axes->True,AspectRatio->1/GoldenRatio,
           AxesLabel->{"x","y(x)"},BaseStyle->12]

restart;

ode:=diff(y(x),x)=y(x)-x;

DEtools:-DEplot(ode,[y(x)],x=-5..6,y = -4..3,arrows=curve,linecolor=red,
                  color='magnitude[legacy]',scene=[x,y(x)],
                  font=[TIMES,12], labelfont=[TIMES,16],size=[default,0.618034]);

 

One can change arrowsize, to make it look closer to Mathematica. But hard to pick the correct value each time.

restart;
ode:=diff(y(x),x)=y(x)-x;

DEtools:-DEplot(ode,y(x),x=-5..6,y = -4..3,arrows=curve,arrowsize=1.2,linecolor=red,color='magnitude[legacy]',
     scene=[x,y(x)],font=[TIMES,12], labelfont=[TIMES,16],numpoints =1000,size=[default,0.618034] );

may be inttrans:-laplace does not work well with mapping on list. I do not know. Here is a workaround
 

ode_sys:=2*diff(x(t),t$2) + 6*x(t) - 2*y(t) = 0, diff(y(t),t$2) + 2*y(t) - 2*x(t) = 0;
lsol:=map(X->inttrans:-laplace(X,t,s),[ode_sys])

 

I noticed this since 

          lsol:=inttrans:-laplace({ode_sys},t,s)

worked OK but has the problem you mentioned, but 

           lsol:=inttrans:-laplace([ode_sys],t,s)

Gives error

Which for me makes no sense., So I do not think inttrans:-laplace is listable function. In Maple. to be safe, I always use explicit map on things,

I am no expert on this. But basically evalhf  evaluates using hardware floating point. The same if you are using say Fortran or C or C++ and so on. No software emulation is involved. Most modern PC's these days are 64 bit. So you will get  

evalhf(Pi)
3.14159265358979312

This is what you should get in Fortran with double precision. If you use evalf() then software floating point kicks in, my guess is that  Maple uses GNU MPFR 

same as Mathematica.  You can adjust how many decimal points you want when using evalf but not with evalhf.  This is done by changing Digits or passing as argument the value of Digits you want used.

evalf(Pi,16)
3.141592653589793

evalf(Pi,50)
3.1415926535897932384626433832795028841971693993751

You can't get more than 16 decimals with hardware (unless you use quad precision or 128 bit  hardware)

So the bottom line, if you want your numerical calculations in Maple to give same results as say with Fortran or C, use hardware floating point. If you do not care, set Digits very high and you get software emulation which is little slower but result will be more accurate.

I myself always use exact numbers since I only do pure symbolic calculations, so do not do any evalf or evalhf stuff. But if you are doing more numerical calculations, say Finite elements in Maple, this can affect your calculations and which way to do it.

It is having hard time with the max. Try piecewise instead then it works

r:=t->Unit('W'/'m'^2)*piecewise(t/Unit('s')>0,t/Unit('s'),true,0);
plot(r(t),  t = -1*Unit('s') .. 2*Unit('s'),axes=boxed);

Because, according to Maple,  -5*x < -5*y  and -5*(x < y) are not the same:

This is either Maple's own type of math, or a bug. I have no idea.

another possible option is 

            map( X-> myf(op(X)), mylist)

 

f:=x->2*sin(x)+1/(2*x)-1;
evalf(allvalues(solve(f(x)=0,x)))

0.2392293076 + 0.4382263889*I, 0.2392293076 - 0.4382263889*I, -3.744173209, 2.721189630, -5.708231047, 6.764610627

or may be you meant this f

f:=x->2*sin(x)+1/2*x-1;
evalf(allvalues(solve(f(x)=0,x)))

-4.504657440 + 1.095023946*I, -4.504657440 - 1.095023946*I, 3.535612202, 0.4090496716, 5.308993144

The latex generated is not good. Its uses the old latex picture environment. If you switch to Tikz latex, then it fixes the problem.

\documentclass{amsart}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,hobby}
\begin{document}

%This code is translation of Maple code but used tikz.
\resizebox{150pt}{150pt}{%
\begin{tikzpicture}
\draw [line width=1cm] plot [smooth] coordinates {(60.78,187.36)(62.00,197.59)(63.22,207.82) };
\draw [line width=1cm] plot [smooth] coordinates {(60.78,187.36)(54.80,168.00)(48.83,148.65) };
\draw [line width=1cm] plot [smooth] coordinates {(60.78,187.36)(73.15,192.54)(85.53,197.72) };
\draw [line width=1cm]  plot [smooth] coordinates {(63.22,207.82)(47.73,191.76)(32.23,175.70)};
\draw  [line width=1cm] plot [smooth] coordinates {(63.22,207.82)(87.29,226.23)(111.36,244.64)};
\draw  [line width=1cm] plot [smooth] coordinates {(32.23,175.70)(35.77,153.14)(39.31,130.58)};
\draw [line width=1cm]  plot [smooth] coordinates {(32.23,175.70)(22.11,179.19)(12.00,182.69)};
\end{tikzpicture}
}

%This code below generated by Maple
\begin{picture}(300,300)
\thicklines
\linethickness{1pt}
\color[rgb]{0.000,0.000,0.000}\qbezier(60.78,187.36)(62.00,197.59)(63.22,207.82)
\color[rgb]{0.000,0.000,0.000}\qbezier(60.78,187.36)(54.80,168.00)(48.83,148.65)
\color[rgb]{0.000,0.000,0.000}\qbezier(60.78,187.36)(73.15,192.54)(85.53,197.72)
\color[rgb]{0.000,0.000,0.000}\qbezier(63.22,207.82)(47.73,191.76)(32.23,175.70)
\color[rgb]{0.000,0.000,0.000}\qbezier(63.22,207.82)(87.29,226.23)(111.36,244.64)
\color[rgb]{0.000,0.000,0.000}\qbezier(32.23,175.70)(35.77,153.14)(39.31,130.58)
\color[rgb]{0.000,0.000,0.000}\qbezier(32.23,175.70)(22.11,179.19)(12.00,182.69)
\end{picture}

\end{document}

Compiling the above using lualatex with TeXLive, here is the difference

 

 

 

You can see that Tikz is much better and lines are smooth.  Attached is the pdf file.

It might be possible to translate picture to tikz automatically, or by using some macros. You can ask at the tex forum for help on this. 

 

soccer.pdf

 


 

``

eq10 := varepsilon*F(-(V(t)*alpha^4*beta^2 - V(t)*alpha^2*beta^4 - S(t)*alpha^4*beta^2 + S(t)*alpha^2*beta^4 + X(t)*beta^4 - Z(t)*alpha^4 + S(t)*alpha^4 - S(t)*beta^4 - X(t)*beta^2 + Z(t)*alpha^2 - S(t)*alpha^2 + S(t)*beta^2)/(alpha^2*(alpha^2 - 1)*(alpha^2 - beta^2)*beta^2*(beta^2 - 1)), (W(t)*alpha^3*beta - W(t)*alpha*beta^3 + Y(t)*beta^3 - U(t)*alpha^3 - Y(t)*beta + U(t)*alpha)/((alpha^2*beta^2 - alpha^2 - beta^2 + 1)*beta*alpha*(alpha^2 - beta^2)), (X(t)*beta^2 - Z(t)*alpha^2 + V(t)*alpha^2 - V(t)*beta^2 - X(t) + Z(t))/((alpha^2 - beta^2)*(beta^2 - 1)*(alpha^2 - 1)), -(Y(t)*alpha*beta^2 - U(t)*alpha^2*beta + W(t)*alpha^2 - W(t)*beta^2 - Y(t)*alpha + beta*U(t))/((alpha^2 - beta^2)*(alpha^2*beta^2 - alpha^2 - beta^2 + 1)), -(X(t)*alpha^2*beta^2 - Z(t)*alpha^2*beta^2 - X(t)*alpha^2 + beta^2*Z(t) + V(t)*alpha^2 - V(t)*beta^2)/((alpha^2 - beta^2)*(beta^2 - 1)*(alpha^2 - 1)), (Y(t)*alpha^3*beta^2 - U(t)*alpha^2*beta^3 - Y(t)*alpha^3 + beta^3*U(t) + W(t)*alpha^2 - W(t)*beta^2)/((alpha^2 - beta^2)*(alpha^2*beta^2 - alpha^2 - beta^2 + 1)), (X(t)*alpha^4*beta^2 - Z(t)*alpha^2*beta^4 - X(t)*alpha^4 + beta^4*Z(t) + V(t)*alpha^2 - V(t)*beta^2)/((alpha^2 - beta^2)*(beta^2 - 1)*(alpha^2 - 1))) - Y(t)*alpha;

varepsilon*F(-(V(t)*alpha^4*beta^2-V(t)*alpha^2*beta^4-S(t)*alpha^4*beta^2+S(t)*alpha^2*beta^4+X(t)*beta^4-Z(t)*alpha^4+S(t)*alpha^4-S(t)*beta^4-X(t)*beta^2+Z(t)*alpha^2-S(t)*alpha^2+S(t)*beta^2)/(alpha^2*(alpha^2-1)*(alpha^2-beta^2)*beta^2*(beta^2-1)), (W(t)*alpha^3*beta-W(t)*alpha*beta^3+Y(t)*beta^3-U(t)*alpha^3-Y(t)*beta+U(t)*alpha)/((alpha^2*beta^2-alpha^2-beta^2+1)*beta*alpha*(alpha^2-beta^2)), (X(t)*beta^2-Z(t)*alpha^2+V(t)*alpha^2-V(t)*beta^2-X(t)+Z(t))/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)), -(Y(t)*alpha*beta^2-U(t)*alpha^2*beta+W(t)*alpha^2-W(t)*beta^2-Y(t)*alpha+beta*U(t))/((alpha^2-beta^2)*(alpha^2*beta^2-alpha^2-beta^2+1)), -(X(t)*alpha^2*beta^2-Z(t)*alpha^2*beta^2-X(t)*alpha^2+beta^2*Z(t)+V(t)*alpha^2-V(t)*beta^2)/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)), (Y(t)*alpha^3*beta^2-U(t)*alpha^2*beta^3-Y(t)*alpha^3+beta^3*U(t)+W(t)*alpha^2-W(t)*beta^2)/((alpha^2-beta^2)*(alpha^2*beta^2-alpha^2-beta^2+1)), (X(t)*alpha^4*beta^2-Z(t)*alpha^2*beta^4-X(t)*alpha^4+beta^4*Z(t)+V(t)*alpha^2-V(t)*beta^2)/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)))-Y(t)*alpha

Typesetting:-Unsuppress('all');
Typesetting:-Suppress([V(t),S(t),W(t),X(t),Y(t),U(t),Z(t)]);     
eq10;

varepsilon*F(-(V(t)*alpha^4*beta^2-V(t)*alpha^2*beta^4-S(t)*alpha^4*beta^2+S(t)*alpha^2*beta^4+X(t)*beta^4-Z(t)*alpha^4+S(t)*alpha^4-S(t)*beta^4-X(t)*beta^2+Z(t)*alpha^2-S(t)*alpha^2+S(t)*beta^2)/(alpha^2*(alpha^2-1)*(alpha^2-beta^2)*beta^2*(beta^2-1)), (W(t)*alpha^3*beta-W(t)*alpha*beta^3+Y(t)*beta^3-U(t)*alpha^3-Y(t)*beta+U(t)*alpha)/((alpha^2*beta^2-alpha^2-beta^2+1)*beta*alpha*(alpha^2-beta^2)), (X(t)*beta^2-Z(t)*alpha^2+V(t)*alpha^2-V(t)*beta^2-X(t)+Z(t))/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)), -(Y(t)*alpha*beta^2-U(t)*alpha^2*beta+W(t)*alpha^2-W(t)*beta^2-Y(t)*alpha+beta*U(t))/((alpha^2-beta^2)*(alpha^2*beta^2-alpha^2-beta^2+1)), -(X(t)*alpha^2*beta^2-Z(t)*alpha^2*beta^2-X(t)*alpha^2+beta^2*Z(t)+V(t)*alpha^2-V(t)*beta^2)/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)), (Y(t)*alpha^3*beta^2-U(t)*alpha^2*beta^3-Y(t)*alpha^3+beta^3*U(t)+W(t)*alpha^2-W(t)*beta^2)/((alpha^2-beta^2)*(alpha^2*beta^2-alpha^2-beta^2+1)), (X(t)*alpha^4*beta^2-Z(t)*alpha^2*beta^4-X(t)*alpha^4+beta^4*Z(t)+V(t)*alpha^2-V(t)*beta^2)/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)))-Y(t)*alpha

Typesetting:-Unsuppress('all');
eq10;

varepsilon*F(-(V(t)*alpha^4*beta^2-V(t)*alpha^2*beta^4-S(t)*alpha^4*beta^2+S(t)*alpha^2*beta^4+X(t)*beta^4-Z(t)*alpha^4+S(t)*alpha^4-S(t)*beta^4-X(t)*beta^2+Z(t)*alpha^2-S(t)*alpha^2+S(t)*beta^2)/(alpha^2*(alpha^2-1)*(alpha^2-beta^2)*beta^2*(beta^2-1)), (W(t)*alpha^3*beta-W(t)*alpha*beta^3+Y(t)*beta^3-U(t)*alpha^3-Y(t)*beta+U(t)*alpha)/((alpha^2*beta^2-alpha^2-beta^2+1)*beta*alpha*(alpha^2-beta^2)), (X(t)*beta^2-Z(t)*alpha^2+V(t)*alpha^2-V(t)*beta^2-X(t)+Z(t))/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)), -(Y(t)*alpha*beta^2-U(t)*alpha^2*beta+W(t)*alpha^2-W(t)*beta^2-Y(t)*alpha+beta*U(t))/((alpha^2-beta^2)*(alpha^2*beta^2-alpha^2-beta^2+1)), -(X(t)*alpha^2*beta^2-Z(t)*alpha^2*beta^2-X(t)*alpha^2+beta^2*Z(t)+V(t)*alpha^2-V(t)*beta^2)/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)), (Y(t)*alpha^3*beta^2-U(t)*alpha^2*beta^3-Y(t)*alpha^3+beta^3*U(t)+W(t)*alpha^2-W(t)*beta^2)/((alpha^2-beta^2)*(alpha^2*beta^2-alpha^2-beta^2+1)), (X(t)*alpha^4*beta^2-Z(t)*alpha^2*beta^4-X(t)*alpha^4+beta^4*Z(t)+V(t)*alpha^2-V(t)*beta^2)/((alpha^2-beta^2)*(beta^2-1)*(alpha^2-1)))-Y(t)*alpha

 


 

Download suppress.mw

It seems due to build-in immediate simplifications. 

a<=b and b>=a are immediately simplified to same thing and placed in same memory location before it reaches the set command.

addressof(a<=b)
                      36893490551756576564

addressof(b>=a)
                      36893490551756576564

But this is not the case for a=b and b=a. These remain internally as different objects in different memory locations

addressof(a=b)
                      36893490551757501180

addressof(b=a)
                      36893490551757501204

Also set does not do simplification either.

{a=b,2*a=2*b}

gives {a = b, 2*a = 2*b}  and not {a=b} 

I would use sprintf also myself, but an answer is given using that method. 

You could also use StringTools to do all of this.

fix_number:=proc(n::numeric,k::posint,$)
   local L::list:=StringTools:-Split(String(n),".");
   local s::string,s0::string,N::integer;

   if nops(L)=1 then
      RETURN(n);
   fi;

   if StringTools:-Length(L[2])>k then
      L[2]:=L[2][1..k];
   fi;

   s:=StringTools:-Reverse(L[2]);
   N:=0;
   #count how many trailing zeros there are
   for s0 in s  do 
       if s0="0" then
          N:=N+1;
       else
          break;
       fi;
   od;
   L[2]:=L[2][1..StringTools:-Length(L[2])-N];
   RETURN(parse(cat(L[1],".",L[2])))
     
end proc:

The above takes in a number and does the conversion on it as needed. For example

 

Now to use this function simply map it on the matrix. Using given Matrix in the answer below to compare with:

A := Matrix(3,3, (i,j) -> 1.0/(i+j));
map(X->fix_number(X,4),A)

 

expr:=a*b+c*(d+e)+f+g+h*(k*p+l)
[op(expr)]

I see now you said the input is string? In this case

expr:="a*b+c*(d+e)+f+g+h*(k*p+l)";
expr:=parse(expr);
map(X->String(X),[op(expr)])

If you do not like map, you can use ~

expr:="a*b+c*(d+e)+f+g+h*(k*p+l)";
expr:=parse(expr);
String~([op(expr)])

ps. converted your post to question.

To do what you want do the following

with(Student[Calculus1]):
res:=ShowSolution(Diff(ln(x),x));
latex(res)

Copy the latex output generated to your latex editor and put it inside \[ ...  \] to make the following file and then compile the file using either pdflatex or lualatex (need to install these on your PC. On Linux, use TexLive, on windows use MikeTex, the mac also has its own Latex, google it to find the right one to use).

\documentclass[12pt]{book}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{maple}
\begin{document}
\[ %make sure to add this 
\begin{array}{ccc}
 & {} & \textrm{Differentiation Steps} 
\\
 {} & {} & \frac{d}{d x}\ln \! \left(x \right) 
\\
 \textrm{▫} & {} & \textrm{1. Apply the}\textrm{natural logarithm}\textrm{rule} 
\\
 {} & \textrm{◦} & \textrm{Recall the definition of the}\textrm{natural logarithm}\textrm{rule} 
\\
 {} & {} & \frac{d}{d x}\ln \! \left(x \right)=\frac{1}{x} 
\\
  & {} & \textrm{This gives:} 
\\
 {} & {} & \frac{1}{x} 
\end{array}
\]%make sure to add this 

\end{document}

Which will give

Since you are running this from command line, you can't really save worksheet as Latex. But you can simply modify your .mpl to automatically do the above. i,e. generate the latex, save the latex to a latex file, then at the end, just add a compile command to your script to compile the latex to pdf. If you also call tex4ht, you can also convert it to HTML.


 

with(Student[Calculus1]):
res:=ShowSolution(Diff(ln(x),x));

"[[,,"Differentiation Steps"],[,,(&DifferentialD;)/(&DifferentialD;x) ln(x)],["&EmptyVerySmallSquare;",,"1. Apply the" "natural logarithm" "rule"],[,"?","Recall the definition of the" "natural logarithm" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) ln(x)=1/x],[,,"This gives:"],[,,1/x]]6""

latex(res)

\begin{array}{ccc}
 & {} & \textrm{Differentiation Steps}
\\
 {} & {} & \frac{d}{d x}\ln \! \left(x \right)
\\
 \textrm{▫} & {} & \textrm{1. Apply the}\textrm{natural logarithm}\textrm{rule}
\\
 {} & \textrm{◦} & \textrm{Recall the definition of the}\textrm{natural logarithm}\textrm{rule}
\\
 {} & {} & \frac{d}{d x}\ln \! \left(x \right)=\frac{1}{x}
\\
  & {} & \textrm{This gives:}
\\
 {} & {} & \frac{1}{x}
\end{array}

 


 

Download convert_steps_to_latex.mw

 

in worksheet, the command I use is   

interface(rtablesize=30);

to make it show 30 rows. You can changes this as needed. I do not know if this works in document mode or Maple learn and other environments. It works for me in worksheet mode.

two possible ways. If you want the result to have the variable name in it, use PDEtools:-Solve(). If you just want the value itself, use solve().

 

restart;

eq:=(3*y - 2)/3 + (2*y + 3)/3 = (y + 7)/6
solve(eq,y)
PDEtools:-Solve(eq,y)

 

5 6 7 8 9 10 11 Last Page 7 of 20