nm

8150 Reputation

19 Badges

11 years, 146 days

MaplePrimes Activity


These are answers submitted by nm

may be

A :=<<4,2,-1>|<2,4,3>|<-1,3,5>>:
b :=<1,0,0>:
sol:=LinearAlgebra:-LinearSolve(A, b)
seq( assign(x||i = sol[i]),  i = 1..numelems(sol))
x1,x2,x3

One option could be to use simplify with side relation

restart;

eq:=V = Vx/(a*s^2 + b*s + c);
normal(lhs(eq)-rhs(eq)=0);
simplify(%,{V*s=_Z});
solve(%,_Z)

eq:=V = Vx/(a*s^2 + b*s + c);
normal(lhs(eq)-rhs(eq)=0);
simplify(%,{V*s^2=_Z});
solve(%,_Z)

You could also use algsubs

eq:=V = Vx/(a*s^2 + b*s + c);
normal(lhs(eq)-rhs(eq)=0);
algsubs(V*s=_Z,%);
solve(%,_Z)

eq:=V = Vx/(a*s^2 + b*s + c);
normal(lhs(eq)-rhs(eq)=0);
algsubs(V*s^2=_Z,%);
solve(%,_Z)

Gives same answers as above. I am sure there are more ways to do this in Maple.

I do not know if this is what you wanted but you can try

p := 2*u - 2/3*(a - 1)*(a + 1)*u^3 + (26/45*a^4 - 4/9*a^2 + 26/45)*u^5 + O(u^6):
convert(p,polynom);
PolynomialTools:-Splits(%,u);

 

you can't do that since it is not legal Maple code. Also you wrote local x=0.0;  when it should have been local x:=0.0; as a work around this is what I do, and I do this alot, it is one of the nice features of Maple to be able to declare local variables inside a BLOCK within a proc like this. These local variable inside a proc are only local to the BLOCK they are in. This is very common thing to do in Languages like Ada and Pascal for example. 

tSound:=proc(xMic,yMic,zMic,xGun,yGun,zGun,mode)  
global vSound;  
local locMic:=Vector([xMic,yMix,zMix]);  
local locGun:=Vector([xGun,yGun,zGun]);   
local delGunToMix;   

if mode=1 then #`direct  `    

    proc() #LOCAL BLOCK
         local x:=0.0;  # now it works
         delGunToMix:=locMic-locGun;    
    end proc();

    return vSound*Norm(delGunToMix);  
elif  mode=2 then 
      NULL;
      #`reflect off wall at z=0`        
end if;   

return 0.0;  
end proc:

why not use the insert code snippet when you post code, instead of just pasting it like you did? It is easier to read in code snippet. btw, you are not using anywhere, but I assume this was just an example you had.

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

 

 

It should return k1

Try

restart;
fa := unapply(piecewise(0 < x and x < a, k1, a < x and x < b, k2), x):
simplify(fa(x),assume=[0 < x,x < a])

 

 

1 2 3 4 5 6 7 Last Page 1 of 14