nm

11558 Reputation

20 Badges

13 years, 135 days

MaplePrimes Activity


These are answers submitted by nm

if you use mul instead of product you could use, for specific the following

restart;
p:=(x,n)->expand(mul( (x+i), i=1..n)):
p(x,5);
coeff( %,x^2)

 

p(x,10);
coeff( %,x^2)

if you use product then it does not seem possible since specific value of n is not known:

restart;
p:=(x,n)->product( (x+i), i=1..n);
p(x,n)

Newton's law of cooling is    q'(t) + k*( q(t) - 25) = 0.

I do not know why you have "t" in the right side. 

I am will solve it using 0 on right side.  You can always change it if you want, but that is not the Newton law of cooling I know.  Why do you have time on the right side? Is there a heating source in the room that generates heat that increases with time  linearly? This is not physically possible.

restart;
k:=2;
ode:=diff(q(t),t)+k*(q(t)-25)=0;
ic:=q(0)=100;
sol:=dsolve([ode,ic]);
#temp after 30 minutes.
evalf(eval(rhs(sol),t=30));
plot(rhs(sol),t=0..30, view=[0..30,1..100]);

So it will at room temp. After 30 minutes. You have very fast cooling there due to very large k. Normally k is a very small value..

Here is the plot of body temp. vs. time

To find the time to reach 50 degrees, solve the equation:

#find how long it takes to go to 50;
eq:=50=rhs(sol);
evalf(solve(eq,t));

0.5493061445

A little over 1/2 second.

You can repeate the same if you want to have "t" on the RHS of the ode.

 

Here is a version with upper case E for the fortran notation

When running the Maple code at the end, it will generate this Latex code

\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow}
\renewcommand{\arraystretch}{1.2}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[hbt!]
\begin{center}
\begin{tabular}{|c|c|c|c|}\hline
\rowcolor{Gray} $x$&$t$&$f \! \left(x , t\right)$&$g \! \left(x , t\right)$\\ \hline\hline 
$ 0.125$&$ 0.125$&$ 0.015625$&$ 1.953\, \mathrm{E}^{-03}$ \\ \hline 
$ 0.125$&$ 0.375$&$ 0.046875$&$ 5.859\, \mathrm{E}^{-03}$ \\ \hline 
$ 0.125$&$ 0.625$&$ 0.078125$&$ 9.766\, \mathrm{E}^{-03}$ \\ \hline 
$ 0.125$&$ 0.875$&$ 0.109375$&$ 1.367\, \mathrm{E}^{-02}$ \\ \hline 
$ 0.375$&$ 0.125$&$ 0.046875$&$ 1.758\, \mathrm{E}^{-02}$ \\ \hline 
$ 0.375$&$ 0.375$&$ 0.140625$&$ 5.273\, \mathrm{E}^{-02}$ \\ \hline 
$ 0.375$&$ 0.625$&$ 0.234375$&$ 8.789\, \mathrm{E}^{-02}$ \\ \hline 
$ 0.375$&$ 0.875$&$ 0.328125$&$ 1.230\, \mathrm{E}^{-01}$ \\ \hline 
$ 0.625$&$ 0.125$&$ 0.078125$&$ 4.883\, \mathrm{E}^{-02}$ \\ \hline 
$ 0.625$&$ 0.375$&$ 0.234375$&$ 1.465\, \mathrm{E}^{-01}$ \\ \hline 
$ 0.625$&$ 0.625$&$ 0.390625$&$ 2.441\, \mathrm{E}^{-01}$ \\ \hline 
$ 0.625$&$ 0.875$&$ 0.546875$&$ 3.418\, \mathrm{E}^{-01}$ \\ \hline 
$ 0.875$&$ 0.125$&$ 0.109375$&$ 9.570\, \mathrm{E}^{-02}$ \\ \hline 
$ 0.875$&$ 0.375$&$ 0.328125$&$ 2.871\, \mathrm{E}^{-01}$ \\ \hline 
$ 0.875$&$ 0.625$&$ 0.546875$&$ 4.785\, \mathrm{E}^{-01}$ \\ \hline 
$ 0.875$&$ 0.875$&$ 0.765625$&$ 6.699\, \mathrm{E}^{-01}$ \\ \hline 
\end{tabular}
\end{center}
\end{table}
\end{document}

Which you can compile using your favourite Latex compiler. The Maple code uses 

I kept the exponent of E as string, so it shows as "-03" instead of -3. To have the same size for all numbers. You can easily change it if you want -3 instead.


 

restart:
interface(rtablesize=20):
f:=(x,t)->x*t;
g:=(x,t)->x^2*t;

B:=Matrix([seq(seq([i,j,f(i,j),g(i,j)],j=0.125..0.875, 0.25),i=0.125..0.875,0.25)]);

convert_it:=proc(matrix_entry)
  local res;
  res:= nprintf(`#mn(\"%1.3e\");`,matrix_entry);
  res:= convert~(res,string);
  res:= StringTools:-Delete(res,1..5);
  res:= StringTools:-Delete(res,-3..-1);
  res:= StringTools:-Split(res,"e");
  return parse(res[1]),res[2]
end proc:

toX:=proc(x)
  Latex(x,output=string);
end proc:

Lat:=proc(M::Matrix,header::list)::string;
  local s::string:="";
  local nRows::posint;
  local nCols::posint;
  local N,item;
  local i,j;
  local the_number,the_exponent;
  
  nRows,nCols:=LinearAlgebra:-Dimension(M);

  s:=cat("\\documentclass{article}
\\usepackage{amsmath}
\\usepackage{multirow}
\\renewcommand{\\arraystretch}{1.2}
\\usepackage{color, colortbl}
\\definecolor{Gray}{gray}{0.9}
\\begin{document}
\\begin{table}[hbt!]
\\begin{center}
\\begin{tabular}{|",seq("c|",i=1..nCols),"}\\hline
\\rowcolor{Gray} ");
    for N,item in header do        
        if N<numelems(header) then
           s:=cat(s,"$",toX(parse(item)),"$&");
        else
           s:=cat(s,"$",toX(parse(item)),"$\\\\ \\hline\\hline \n");
        fi;
    od;
    
    for i from 1 to nRows do
        for j from 1 to nCols do
            if j=nCols then
               the_number,the_exponent:=convert_it(M[i,j]);
               s:=cat(s,"$",toX(the_number),"\\, \\mathrm{E}^{",the_exponent,"}$ \\\\ \\hline \n");
            else
               s:=cat(s,"$",toX(M[i,j]),"$&");
            fi;        
        od;
    od;
    
    s:=cat(s,"\\end{tabular}
\\end{center}
\\end{table}
\\end{document}
");
    return s;        

  
 end proc:
  

f := proc (x, t) options operator, arrow; x*t end proc

g := proc (x, t) options operator, arrow; x^2*t end proc

Matrix(%id = 36893490297603924324)

s:=Lat(B,[x,t,`f(x,t)`,`g(x,t)`]):
printf("%s",s)

\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow}
\renewcommand{\arraystretch}{1.2}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[hbt!]
\begin{center}
\begin{tabular}{|c|c|c|c|}\hline
\rowcolor{Gray} $x$&$t$&$f \! \left(x , t\right)$&$g \! \left(x , t\right)$\\ \hline\hline
$ 0.125$&$ 0.125$&$ 0.015625$&$ 1.953\, \mathrm{E}^{-03}$ \\ \hline
$ 0.125$&$ 0.375$&$ 0.046875$&$ 5.859\, \mathrm{E}^{-03}$ \\ \hline
$ 0.125$&$ 0.625$&$ 0.078125$&$ 9.766\, \mathrm{E}^{-03}$ \\ \hline
$ 0.125$&$ 0.875$&$ 0.109375$&$ 1.367\, \mathrm{E}^{-02}$ \\ \hline
$ 0.375$&$ 0.125$&$ 0.046875$&$ 1.758\, \mathrm{E}^{-02}$ \\ \hline
$ 0.375$&$ 0.375$&$ 0.140625$&$ 5.273\, \mathrm{E}^{-02}$ \\ \hline
$ 0.375$&$ 0.625$&$ 0.234375$&$ 8.789\, \mathrm{E}^{-02}$ \\ \hline
$ 0.375$&$ 0.875$&$ 0.328125$&$ 1.230\, \mathrm{E}^{-01}$ \\ \hline
$ 0.625$&$ 0.125$&$ 0.078125$&$ 4.883\, \mathrm{E}^{-02}$ \\ \hline
$ 0.625$&$ 0.375$&$ 0.234375$&$ 1.465\, \mathrm{E}^{-01}$ \\ \hline
$ 0.625$&$ 0.625$&$ 0.390625$&$ 2.441\, \mathrm{E}^{-01}$ \\ \hline
$ 0.625$&$ 0.875$&$ 0.546875$&$ 3.418\, \mathrm{E}^{-01}$ \\ \hline
$ 0.875$&$ 0.125$&$ 0.109375$&$ 9.570\, \mathrm{E}^{-02}$ \\ \hline
$ 0.875$&$ 0.375$&$ 0.328125$&$ 2.871\, \mathrm{E}^{-01}$ \\ \hline
$ 0.875$&$ 0.625$&$ 0.546875$&$ 4.785\, \mathrm{E}^{-01}$ \\ \hline
$ 0.875$&$ 0.875$&$ 0.765625$&$ 6.699\, \mathrm{E}^{-01}$ \\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}

 


 

Download code.mw

 

restart;
pde1:= diff(C(x,t),t)=d* diff(C(x,t),x$2)- k*epsilon(x)*C(x,t);
pde2:= diff(epsilon(x),x)=-mu*k*epsilon(x)*C(x,t);

pdsolve([pde1,pde2],[C(x,t),epsilon(x)]) assuming x>a,x<=b,t>0

....  Other long and complicated solutions are also given in addition to the above, in terms or RootOf (ps. I renamed your "D2" to "d"

 

Maple 2020.2

On windows:

Click Start->  Then type in the search box "environment" and select the tiop option. This will bring up "System properties". Click on botton called "Environemnt variables" . In the top window, for "User Variables", click "NEW" and add  Variable caled TEXINPUTS and give it value of the full path of the folder where you your Maple style files are.  On windows it is in

"C:\Program Files\Maple 2020\etc"

and click OK. And start  exnicCenter and compile, now it will find it. Make sure in your Latex file you include it as follows (if it is not allready there)

    \usepackage{maplestd2e}

Now MikTex compiler, when invoked by TexnicCenter will lookup this environment variable and use it to search for maple latex style files.

There is another method to do this, Using MIKTEX Console and then going to settings->Directories and adding the above Maple folder path to the TEXMF folders listed there allready.  

I find editing the Environemnt variables and adding TEXINPUTS easier. 

 

b:=(X__2-I__22)/((x__1-I__11)*(X__2-I__22)-I__12*I__21);

You have a typo there. It should be X__1 and not lower case x__1 

simplify(a) almost gets there:

But to get to exactly b, which is 

I do not know, (could not find direct way, but may be there is). other than looking at it, and do the following

restart;
a:=-(I__22-X__2)/(I__11*I__22-I__11*X__2-I__12*I__21-I__22*X__1+X__1*X__2);
a:=simplify(a);
term:=X__1 - I__11;
algsubs(term=A,a);
collect(%,A):
subs(A=term,%);

Getting CAS to give the same exact form one wants, is one of the hardest things. sometimes CAS has it own way of formating expressions.   So some manual steps would be needed.

 

 

You could check the difference is zero between each corresponding elements?

V1 := Vector[column](8, [1, 2, 2, 1, 3, A, B, 1/(A + B)^2]);
V2 := Vector[column](8, [1, 2, 2, 1, 3, A, B, 1/(A^2 + 2*A*B + B^2)]);
ArrayTools:-IsZero(simplify(V1-V2))

      true

 

I generate everything from Maple using Latex.  CAS systems (either Maple or Mathematica) can't compete with Latex when it comes to formating output. 

ps. I get different numbers for f(x,t) and g(x,t). May be you used different definition than you showed

Running this Maple code below and pasting the output into your Latex editor and compiling will generate the above table.
 

restart;

f:=(x,t)->x*t:
g:=(x,t)->x^2*t:
toX:=s->Latex(s,output=string):
val:=[seq(i,i=0.125..0.875,0.25)]:
s:="":
s:=cat(s,"\\documentclass{article}
\\usepackage{multirow}
\\renewcommand{\\arraystretch}{1.2}
\\usepackage{color, colortbl}
\\definecolor{Gray}{gray}{0.9}
\\begin{document}
\\begin{table}[hbt!]
\\begin{center}
\\begin{tabular}{|c|c|c|c|}\\hline
\\rowcolor{Gray}$x$ & $t$ & $f(x,t)$ & $g(x,t)$\\\\ \\hline\\hline \n"):
for x in val do
    for N,t in val do
        if N=1 then
            s:=cat(s,"\\multirow{4}{*}{$",toX(x),"$}&");
        else
            s:=cat(s,"&");
        fi;
        s:=cat(s,"$",toX(t),"$&$",toX(f(x,t)),"$&$",toX(g(x,t)),"$\\\\ "):
        if N=numelems(val) then
           s:=cat(s,"\\hline \n");
        fi:
    od:
od:
s:=cat(s,"\\end{tabular}
\\end{center}
\\end{table}
\\end{document}"):

printf("%s",s)

\documentclass{article}
\usepackage{multirow}
\renewcommand{\arraystretch}{1.2}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[hbt!]
\begin{center}
\begin{tabular}{|c|c|c|c|}\hline
\rowcolor{Gray}$x$ & $t$ & $f(x,t)$ & $g(x,t)$\\ \hline\hline
\multirow{4}{*}{$ 0.125$}&$ 0.125$&$ 0.015625$&$ 0.001953125$\\ &$ 0.375$&$ 0.046875$&$ 0.005859375$\\ &$ 0.625$&$ 0.078125$&$ 0.009765625$\\ &$ 0.875$&$ 0.109375$&$ 0.013671875$\\ \hline
\multirow{4}{*}{$ 0.375$}&$ 0.125$&$ 0.046875$&$ 0.017578125$\\ &$ 0.375$&$ 0.140625$&$ 0.052734375$\\ &$ 0.625$&$ 0.234375$&$ 0.087890625$\\ &$ 0.875$&$ 0.328125$&$ 0.123046875$\\ \hline
\multirow{4}{*}{$ 0.625$}&$ 0.125$&$ 0.078125$&$ 0.048828125$\\ &$ 0.375$&$ 0.234375$&$ 0.146484375$\\ &$ 0.625$&$ 0.390625$&$ 0.244140625$\\ &$ 0.875$&$ 0.546875$&$ 0.341796875$\\ \hline
\multirow{4}{*}{$ 0.875$}&$ 0.125$&$ 0.109375$&$ 0.095703125$\\ &$ 0.375$&$ 0.328125$&$ 0.287109375$\\ &$ 0.625$&$ 0.546875$&$ 0.478515625$\\ &$ 0.875$&$ 0.765625$&$ 0.669921875$\\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}

#copy paste the above using the mouse to your Latex editor and compile it.


 

Download make_table.mw

one possibility

restart;
F:=x*y^2-x;
G:=x*sin(Pi*x);
solve([F,G],[x,y]);

_EnvAllSolutions:=true;
solve([F,G],[x,y])

or

restart;
F:=x*y^2-x;
G:=x*sin(Pi*x);
solve([F,G],[x,y],allsolutions=true);

I would not do this. This is the wrong way to program.  

restart;
sol:=solve(x^2+3*x+4=0,x);
assign(('A','B')=sol):
         

A better way is to just assign all the solutions to one variable. A list. Then use indexing to access each solution.

The less variables there are, the more control on your code you have., You do not want a function with 100 variables in it.

The above assumes there are 2 solutions ofcourse. In code, if you want to do this in a more robust way, you'd need to first find the number of solutions, then come up with, at run-time, variable names on the fly, and do the above, so they match.

For example:

Assign solution to list and access sol using [] indexing or iteration

restart;
sol:=[solve(x^2+3*x+4=0,x)];
for N,item in sol do
    print("solution ",N," is ",item);
od;

#or
sol[1];  

sol[2];  #etc..

 

or

restart;
sol:=[solve(x^2+3*x+4=0,x)];
for i from 1 to numelems(sol) do
    print(sol[i]);
od;

Only one variable is needed. sol to store all solutions. No need to come up with other variable names.

I found the problem. I did not look too close before.

To get the arrows, you need to have coupling between the two ODE's. Before you had 

    OnDE:=diff(On(t),t)=(rhs(solEr))/500*60-On(t)/1500*60;

where you replaced the actual Er(t) above. This removed the coupling between the two ODE's.

Instead, you need to just write Er(t) in the second ODE, and Maple will figure it out.  Now Maple see the two ODE's make a system.

If you do not have coupling, then these were 2 separate ODE's and that is why the arrows were missing.

 

restart;
ErDE:=diff(Er(t),t)=30-Er(t)/500*60;
OnDE:=diff(On(t),t)=Er(t)/500*60-On(t)/1500*60; 
initvals := [[Er(0)=0,On(0)=0], [Er(0)=500,On(0)=0],[Er(0)=500,On(0)=1500]];
DEtools:-DEplot( {ErDE,OnDE} , {Er(t),On(t)}, t=0..150, initvals, numpoints=100, linecolour=[blue,red,yellow]); 

 

 

if I understand right, see if this works for you. To make it go by 1,3,5,7,... just add "2" after, so it jump by 2 each time, starting from 1.

 

restart;
h:=x->sin(x)/x;
A:=n->Int(mul(h(x/a),a=1..2*n+1,2),x=0..infinity);

A(2);
A(3);
A(4);

You can add value() to evaluate the integral at end.

in numerical integration, you can't have parameter with no numerical value in the integrand. (how is Maple going to find numerical value if a has no value?)

Assign a some value before calling int, then it will work

a:=.4;
f := (x, y) ->(1/2)*a*(sinh(y-x^2)+tanh(x-y^3)); 
sol := evalf(int(int(f(x, y), x = -6 .. 5), y = -5 .. 5));

or

restart;

Explore( 
   evalf(int(int((1/2)*a*(sinh(y-x^2)+tanh(x-y^3)), x = -6 .. 5), y = -5 .. 5)),
   a=1..10,initialvalues=[a=1],size=[800,60]
);

You can also use Explore, and change the raduis using the slider with the mouse.

 

restart;
Explore(plots:-display( plottools:-sphere([0,0,0],r),view=[-3 .. 3,-3..3,-3..3]),
        r=0.1..3.0,initialvalues=[r=0.5]):

always use exact numbers, unless there is a reason not to

a := 12/100;
kn := n -> (n + 1/2)*Pi/a;
g := (n, x) -> cos(kn(n)*x);
g(1, a);

   0

First 9 10 11 12 13 14 15 Last Page 11 of 19