nm

11018 Reputation

20 Badges

12 years, 281 days

MaplePrimes Activity


These are answers submitted by nm

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)

 

 

seq(`if`(L[i,1]="H",i,NULL),i=1..nops(L));
{%}

 

b := exp(-I*varphi)*sin(theta/2)*cos(theta/2) + cos(theta/2)*exp(I*varphi)*sin(theta/2);
evalc(combine(b));

data:=ssystem("systeminfo"):
data[2];

Issue similar command for Linux and mac.

Is there a simple way to do that without having examine the plots?

May be there is a build in way to this using using DynamicSystems (i.e. give it transfer function and omega (rad/sec), and it gives back the gain in db unit at that frequency).

I do not know now.  I do not use DS very much these days.

But you could always just apply the definition of the gain itself. Given TF = f(s), just replace s by I*w and find the absolute value at the specific w you want, then do 20*log10 of he result. This gives the gain in db at that specific w.  Here is an example

restart;
DS:=DynamicSystems;
sys:=s/(s^2+s+1);
tf:=DS:-TransferFunction(sys):
fr:=DS:-FrequencyResponseSystem(tf);
DS:-MagnitudePlot(fr)

Let us verify by evaluating the gain in db at say w=0.1 and w=0.2 and w=0.6 and w=1 to see if we get same result as show in the above

sysI:=eval(sys,s=I*w):
mag:=abs(eval(sysI,w=0.1)):
20*log10(mag);

mag:=abs(eval(sysI,w=0.2)):
20*log10(mag);

mag:=abs(eval(sysI,w=0.6)):
20*log10(mag);

mag:=abs(eval(sysI,w=1)):
20*log10(mag);

which gives

Which matches the plot.

You can make small function and put the above code in it. somethging like

restart; #we do not need DS
getGainAtFreq:=proc(sys,s::symbol,w)
   eval(sys,s=I*w):
   abs(eval(%,w=0.1)):
   20*log10(%);
end proc:

And now do

sys:=s/(s^2+s+1);

getGainAtFreq(sys,s,0.1);
getGainAtFreq(sys,s,0.2);
getGainAtFreq(sys,s,0.6);

If numbers have no decimal points, as you show in your example, then one possibility might be to convert it to string and get the length.

number:=22;
number_binary:=convert(number,binary);
length(String(number_binary))

   5

does Maple not have build in functions to do this similar to these in Mathematica? https://reference.wolfram.com/language/ref/IntegerDigits.html  it probably does but I could not find them searching. May be they are in some package.

1) 

S:={{a,b},{a,b,c},{b,c},{c}};
select(Z->member(a,Z),S)

2)

X:=[a,b,c];
cartProdSeq:= proc(L::seq(list))
    local Seq::nothing,i::nothing,j;
    option `Copyright (C) 2007, Joseph Riel. All rights reserved.`;
    eval([subs(Seq= seq, foldl(Seq, [cat(i, 1..nargs)], 
                                  seq(cat(i,j)= L[j], j= nargs..1, -1)))])
end proc:
cartProdSeq(X,X);
select(Z->member(a,Z) and member(b,Z),%)

 

Need to tell it from where you are approaching 0

limit( log(x)/x,x=0,right)

There are many ways,. Here are two 

restart;

ode:=diff(y(x),x$2)+diff(y(x),x)+y(x)=0;
sol:=dsolve(ode);

diff(diff(y(x), x), x)+diff(y(x), x)+y(x) = 0

y(x) = _C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)

diff(rhs(sol),x)

-(1/2)*_C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+(1/2)*_C1*exp(-(1/2)*x)*3^(1/2)*cos((1/2)*3^(1/2)*x)-(1/2)*_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)-(1/2)*_C2*exp(-(1/2)*x)*3^(1/2)*sin((1/2)*3^(1/2)*x)

sol := unapply(rhs(sol),x);

proc (x) options operator, arrow; _C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x) end proc

diff(sol(x),x)

-(1/2)*_C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+(1/2)*_C1*exp(-(1/2)*x)*3^(1/2)*cos((1/2)*3^(1/2)*x)-(1/2)*_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)-(1/2)*_C2*exp(-(1/2)*x)*3^(1/2)*sin((1/2)*3^(1/2)*x)

diff(sol(x),x$2)

-(1/2)*_C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)-(1/2)*_C1*exp(-(1/2)*x)*3^(1/2)*cos((1/2)*3^(1/2)*x)-(1/2)*_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)+(1/2)*_C2*exp(-(1/2)*x)*3^(1/2)*sin((1/2)*3^(1/2)*x)

 

Download diff.mw

You can also make y(x) itself a function. But I think it is better to use sol and keep y as free variable.

restart;

ode:=diff(y(x),x$2)+diff(y(x),x)+y(x)=0;
sol:=dsolve(ode);

diff(diff(y(x), x), x)+diff(y(x), x)+y(x) = 0

y(x) = _C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)

y := unapply(rhs(sol),x);
diff(y(x),x)

proc (x) options operator, arrow; _C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x) end proc

-(1/2)*_C1*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)+(1/2)*_C1*exp(-(1/2)*x)*3^(1/2)*cos((1/2)*3^(1/2)*x)-(1/2)*_C2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)-(1/2)*_C2*exp(-(1/2)*x)*3^(1/2)*sin((1/2)*3^(1/2)*x)

 

Download diff2.mw

looks like numerical issue. Try

restart;
sol:=[solve((20 + 20*T + 2*T*(T + 1))*exp(-T) - 10*exp(-2*T) - 2*T - 10 = 0,T)];
evalf~(sol)

Gives

         [-10.0000000000, -0.0000000000]

PDEtools gives just zero as answer

restart;
sol:=PDEtools:-Solve((20 + 20*T + 2*T*(T + 1))*exp(-T) - 10*exp(-2*T) - 2*T - 10 = 0,T);
evalf(sol)

This is hard to solve exactly, so use root finder

restart;
eq:=(20 + 20*T + 2*T*(T + 1))*exp(-T) - 10*exp(-2*T) - 2*T - 10 = 0;
Student:-Calculus1:-Roots(eq, 0..2);

 

         [0, 1.4114548230]

 

Maple 2022.1 on windows 10.

 

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