nm

11458 Reputation

20 Badges

13 years, 77 days

MaplePrimes Activity


These are answers submitted by nm

I do not do plotting much in Maple, so this might not be the optimal solution. it seems to lose the minor ticks though.  There might be a way to also keep these there. I think the problem is that Maple needs a little bit more space, and so it added ticks by skipping every other value. that is why the odd values 5 and -5 do not show up.

 

R:=10:
r:=5:
plot3d( [ ( R+r(u,v)*cos(v))*sin(u),
          ( R+r(u,v)*cos(v))*cos(u),
            r*sin(v)
        ],
            u=0..2*Pi,
            v=0..2*Pi,style=patchnogrid,
            scaling=constrained,
            scaling=constrained,
coordinateview=[-15..15, -15..15,-5..5],tickmarks=[default,default, [seq(i,i=-5..5,2)]],
lightmodel=light3, viewpoint = circleleft);

 

Or you could increase the view to coordinateview=[-15..15, -15..15,-6..6] to give it more space? 

 

Maple uses last name evaluation for number of expressions. But this does not apply to things that are rtable based. This includes Matrix, Vector, and Array etc...

last name evaluations is what you are asking for. This means, when you write A:=C; and then assign some value to C, then when you use A again, you expect it to have same value you assigned to C. This is because Maple used last name evaluation to A.

But this does not work with rtables.  That is why when you print the matrix again, you did not see its value changed after you changed m

I do not know if it is possible to change this. But you can always use eval or subs

restart; 
u:=<-2+m,3+m>;
m:=5;
u;

type(u,'last_name_eval')

false

You can now use eval to force value of m to be used inside rtable

unassign('m');
u:=eval(u,m=5)

Look up last name evaluation in help for more information.

 

I get slighlty different result from that shown.

f:=t->862.979774+1825.011621/((1+1.54943476*e^(-677.0138344*t))^(131537/203808));
convert(f(t),rational)

Copied the integrand to Mathematica and it gives

Copied the result from Mathematica back to Maple

expr:=`(1450669*t)/
  1681 + (4459704101248*
    Hypergeometric2F1[131537/203808, 1, 335345/203808, 
          (36887*E^((342569*t)/506))/(57154 + 
        36887*E^((342569*t)/506))])/
     (1067737900495*(1 + 57154/(E^((342569*t)/506)*36887))^(131537/
       203808))`;
maple_expr:=MmaTranslator:-FromMma(expr);
lprint(maple_expr);


1450669/1681*t+4459704101248/1067737900495*hypergeom([131537/203808, 1],[335345
/203808],36887*exp(342569/506*t)/(57154+36887*exp(342569/506*t)))/(1+57154/
36887/exp(342569/506*t))^(131537/203808)

Compare to answer by Axel 

Here is plot on top of each others, which shows some difference. I am not sure which is the correct one

Axel:=2.695678478*hypergeom([1., 1., 1.645396648],[2., 2.],-1.549434760*exp(-677.0138340*t))*exp(-677.0138340*t)+.95671881+1887.991395*t;
plot([maple_expr,Axel],t=-0.01 .. 0.01)

 How to get time dependence for fixed x?

why do you need to solve this numerically? Maple can give exact analytical answer

restart;
PDE := diff(u(x,t),t)=1/10*diff(u(x,t),x,x);
IBC := u(x,0)=1, u(0,t)=0, D[1](u)(1,t)=0;
sol := pdsolve([PDE,IBC]);

To plot for fixed x, with changing t, simply set x to some value in the above, and plot for changing t.

f:=unapply(subs(infinity=20,rhs(sol)),x,t)

plot(f(1.5,t),t=0..5)

 

Actually Maple's result is correct. 

 

it does not take much time for Maple to access/index into an entry in a list or a set. It happens so fast, that the cpu time do not even register at the scale needed.

SOL:=[1,2,3,4];
CodeTools:-Usage(SOL[1], output = ['cputime', 'output', 'bytesused'])

gives

memory used=1.06KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

Try to use Usage on some operation that actually will use some CPU time and makes Maple think a little more.  Something like

CodeTools:-Usage(dsolve(diff(y(x),x$2)/y(x)+sin(x)=0), output = ['cputime', 'output', 'bytesused'])

which gives

memory used=32.92MiB, alloc change=28.00MiB, cpu time=407.00ms, real time=366.00ms, gc time=62.50ms

 

You did not say how will you use this "table" you want to generate. i.e. is it just for display purposes, or you want to use it later on for computation. This will affect how one can do this.

Another option is

restart;
T := t -> (t+459.47) * 5/9;
convert([seq([t,T(t)],t=100..110)],Matrix)

I am sure there are many ways to do this. One possibility is

ls:=["a", "b", "c", "d", "e"];
n:=numelems(ls);
[seq(ls[i],i=1..n,2)],[seq(ls[i],i=2..n,2)]

or if you do not want to use intermediate variable n

ls:=["a", "b", "c", "d", "e"];
[seq(ls[i],i=1..nops(ls),2)]  ,  [seq(ls[i],i=2..nops(ls),2)]

 

So, what is I in Maple?

By default it is sqrt(-1) 

restart;
I*I

     -1

You change this default using the command interface(imaginaryunit). see help

imaginaryunit  symbol

Specifies the symbol to be used to input the imaginary unit.  

By default, this is I.  

Any occurrences of the specified symbol in Maple input will be 
converted internally to Complex(1).  Any complex numbers displayed 
in Maple output will be displayed as specified by imaginaryunit.  

The specified symbol must be a simple symbol that does 
not require left single quotes.  For example, I and _i are valid, 
whereas `complex/sqrtm1` is not.

Maple 2020.2

 

1) make your code a proc. say foo:=proc(..)  ...  end proc;

2).From Maple worksheet,  issue the command stopat(foo)

3) invoke foo() as normal

4) debugger opens. 

5) type the command   stoperror(`all`) in the small debugger command menu below.

6) hit the continue button you see at the bottom.

7) now Maple will stop at the exact line where it encounters an error.

8) learn how to use the debugger. Even though Maple debugger is primitive compared to modern debuggers such as Matlab's and others, and Maplesoft does not seems to be interested in improving it, it is still useful and worth learning. 

Edit

If it is a syntax error you mean, you can easily find the line as follows.

Maple will give the line number and the exact location on the line where the syntax error is located if you read the code from a file.

You should really use .mpl files anyway for large code. All my Maple code sits in .mpl files. I only use the worksheet to try quick small things, and for loading files, creating library (.mla) and such and for quick testing of something. All my main editing of code is done outside in a text editor.

So simply put your code in a file, say foo.mpl and do   read "foo.mpl". Now you'll see the line number.  Here is an example

Maple 2020.2

 

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. 

 

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