## 9718 Reputation

12 years, 61 days

## MaplePrimes Activity

### These are answers submitted by nm

Here is another approach

find_element:=proc(e,L::list)
local idx;
idx:=ListTools:-Search(e,L);
if idx=0 then
RETURN([]);
elif idx=nops(L) then
RETURN([L[idx]]);
else
RETURN(L[idx+1..-1]);
fi;
end proc;

is_in_order:=proc(N::list,lis::list)::truefalse;
local final_result::truefalse:=true;
local item,r::list:=lis;
for item in N do
r:=find_element(item,r);
if nops(r)=0 then
final_result:=false;
break;
fi;
od:
RETURN(final_result);
end proc:


and now

is_in_order([7,2,4],[2,6,5,7,3,2,9,4])
true

is_in_order([7,2,4],[2,1,4,2,6,7,3,9])
false

is_in_order([7,2,4],[7,4,2,7,2,4])

true

is_in_order([7,2,4],[7,7,7,7,2,2,2,7,4])

true

 > u1 := RootOf(4*_Z^2 + (4*RootOf(60*_Z^3 - 60*_Z^2 + 15*_Z - 1) - 4)*_Z + 4*RootOf(60*_Z^3 - 60*_Z^2 + 15*_Z - 1)^2 - 4*RootOf(60*_Z^3 - 60*_Z^2 + 15*_Z - 1) + 1)

 > DEtools:-remove_RootOf(u1): result:=[allvalues(%)]: map(X->simplify(convert(X,trig)),result);

 >

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