home

PDF (letter size)

PDF (legal size)

my Maple cheat sheet

Nasser M. Abbasi

October 23, 2021   Compiled on October 23, 2021 at 4:19pm  [public]

Contents

 1 How to find a particular solution to ODE?
 2 How to find basis solutions for homogeneous ode?
 3 How to convert Mathematica expression to Maple?
 4 How to debug internal procedures, such as dsolve?
 5 How to display or print source code of a function or procedure in MAPLE?
 6 How to display trace of a function as it runs in maple?
 7 How to display a build in function code?
 8 How to build a LIST or a SET on the fly?
 9 How to make function display more information of what it is doing?
 10 How to solve a differential equation with initial conditions?
 11 How to verify that the ODE solution given is correct?
 12 How to know the type of ODE?
 13 What packages to load for differential equations?
 14 How to plot solution of differential equations?
 15 How to plot a function?
 16 How to run maple from command line?
 17 How to use matrices in maple?
 18 How can maple return more than value from a procedure call?
 19 How does maple handle procedure arguments?
 20 How to define your own data types?
 21 How to find max element in a matrix and its position as same time?
 22 How to create a package?
 23 How to convert from floating point to Hex?
 24 How to find taylor series expansion of functions?
 25 How to print elements of a matrix?
 26 How to find determinant of matrix?
 27 How to generate Hilber matrix?
 28 How to plot matrix data?
 29 How to catch an error from a proc()?
 30 How to convert 3456 to 3,456 ?
 31 How to use units ?
 32 On High precision. Using taylor to solve ODE
 33 How to evaluate catlan number and other sums?
 34 How to write a text file that contains a package, and load it and execute it?
 35 How to find what packages are included in maple
 36 How to plot the gradiant vector field?
 37 How to put the digits of Pi into a list?
 38 Digits of PI in maple and mma
 39 How to find where functions are?
 40 on maple data types
 41 how to extract stuff from a list based on some selection?
 42 how to test if all elements of a matrix are integers?
 43 how to use laplace transform?
 44 questions I have
 45 3D plotting
 46 How to raise each element in a list to a power?
 47 How to generate a sequence with any increment?
 48 What shortcuts are there for matrix manipulation?
 49 How to solve a set of equations for the derivative?
 50 How to solve a set of equations for differentials?
 51 How to plot binary tree
 52 solving problem 12.4 chapter 4, Math 121A, Boas book. using maple
 53 example of doing convergence test in maple
 54 Solving problem math 121A, ch 14, 3.18, Boas book. contour integration
 55 How to find multiple roots to an equation such as \(sin(x) = 0\)
 56 Dr Basti Associated Legendre
 57 Understanding conformal mapping in maple
 58 Is there a way to keep the assumptions but not see the tilda character show up?
 59 Fourier series in maple
 60 How to plot graphs next to each others in a grid like fashion
 61 How to generate Pi on X-axis
 62 How to make output from FunctionAdvisor look better?
 63 How to do partial fractions?
 64 How to generate sequence sum symbolically
 65 Nice plot from Maple
 66 How to check if 2 expressions are the same?
 67 converting series to factorials
 68 How to find what new additions made to Maple?
 69 Maple can’t solve laplace equation and numerically
 70 Some Maple Matrix operations
 71 How set diagonal elements to some value, say 1?
 72 How to multiply roots of a polynomial?
 73 How to plot a surface in 3D?
 74 How to convert trigs to sinc function in an expression
 75 How to find NullSpace and ColumnSpace of a matrix?
 76 How to fix the interface to using Maple notation for input?
 77 How to find all solutions using allvalues ?
 78 How to add one to only the elements of the diagonal of a matrix?
 79 How to search help for updates on some package
 80 How to work with groups in worksheet
 81 How to read code into worksheet?
 82 Code editors for Maple
 83 How to find if package is module or table?
 84 How to replace a string?
 85 How to use geometry and plottools ?
 86 How to simplify log expressions ?
 87 How to simplify hyperbolic expression ?
 88 How to create text file and append string to it?
 89 How to search packages and libraries?
 90 How to numerically solve a BVP ode and plot the solution?
 91 How to find the indicial equation for an ODE?
 92 How to display on screen for specific width?
 93 Maple IDE links
 94 loading, remove and finding what packages loaded
 95 some rules of thumbs when using Maple
 96 How to write derivative
 97 How to solve heat PDE in 1D in Maple 2017?
 98 How to make multiple assumptions on a symbol?
 99 How to make Maple display diff(y(x),x) as \(y'(x)\) or as \(y'\) ?
 100 How to check if expression is an equation?
 101 How to check if expression is a set?
 102 How to set boundary conditions for dsolve or pdsolve?
 103 How to export a plot to PDF?
 104 How to find all roots of complex number
 105 How to convert matrix of matrices to a matrix?
 106 How to do pattern matching in Maple?
  106.1 Example 1
 107 How to find trig indetities?
 108 How to find directional derivative of scalar function?
 109 How to check if name is assigned a value?
 110 How to use dsolve with Lie?
 111 How to select terms with sqrt or radical in them from an expression
 112 How to simplify \(e^{\ln (x)+\ln (y)}\)
 113 How to find all csgn() and replace them by 1
 114 How to replace all abs(expr) by expr
 115 How to find basis for Null space, Row space and column space of matrix?
 116 How to do Gaussian elimination on a Matrix?
 117 How to find Reduced Echelon form of a Matrix?
 118 How add a new row to bottom of matrix?
 119 How to obtain list of all occurances of some function in an expression?
 120 How to replace \(\ln (|x|)\) with \(\ln (x)\) in an expression?
 121 How to find all signum functions in expression and simplify it?
 122 How to do change of variables on the dependent variable for an ODE?
 123 How to find the cofactor matrix of a matrix?
 124 How to make phase plot of second order ODE?
 125 How to normalize eigenvectors?
 126 How to find if some function is present in an expression
 127 How to find all functions in an expression?
 128 How to find all functions in an expression but exclude all build in math functions?
 129 How to obtain a list of all arguments of function?
 130 How to obtain a list of all functions in expression whose first argument is \(z\)?
 131 How to obtain a list of all functions in expression whose second argument is \(t\)?
 132 How to typeset \(\hslash \)?
 133 How to find the Curl of a vector?
 134 How to see all steps in finding RREF form of an augmented matrix?
 135 How to find column space of matrix?
 136 How to use select with own type to find subexpressions?
 137 How to write structured types to match some expressions?
  137.1 type for \(\sin ^m(x)\cos ^n(x)\)
 138 How to use new object method calling in Maple 2021?
 139 How to make a constructor for an Object?
 140 How to make different constructors for an Object?
 141 How to do OOP inheritance?
 142 How to use object as user defined record inside a proc?
 143 Given an expression with indexed variables, how to select only these variables?
 144 How to show step by step for calculus problem?
 145 How to obtain list of files with some extension in folder?
 146 How to delete lines from text file that contains some string?
 147 Given an expression, how to find all variables and functions in it?
 148 How to check if an expression is integer, when it has symbols in it?
 149 How to invert roles of dependent variable and independent variable in an ode?
 150 How to truncate a polynomial?

1 How to find a particular solution to ODE?


To step into the code, do


To print it do


2 How to find basis solutions for homogeneous ode?

Use the output=basis option


3 How to convert Mathematica expression to Maple?


Or


4 How to debug internal procedures, such as dsolve?


Then used the command stopat(f); then called the procedure f(); and now the debugger comes up. Did step command and now it steps inside dsolve

5 How to display or print source code of a function or procedure in MAPLE?

For integration use


Another option


then print(procedure); or eval(procedure_name); for example


Also can use showstat, in this case interface(verboseproc=3) is not needed. Also showstat gives line numbers and I think it is easier to read.


There is also a function by Joe Riel here here is the post by Joe Riel:

"A disadvantage of showstat, particularly if you want to cut and paste the output, is that it includes line numbers. Here is a simple procedure I threw together to remove the line numbers."


To print source code to file using the above, do the following


Now the output will show up in the file "listing.txt" and also no line wrapping. The above I found is the best solution so far to do this.

6 How to display trace of a function as it runs in maple?


also see debug(foo);

Also


See http://www.mapleprimes.com/questions/35951-How-To-Debugtrace-Things-In-Maple

Also look at kernelopts(opaquemodules=true)

Here is a useful post by Carl Love from Maple prime forum that summarizes all of these

Here are four things that you can do to get more information. I have listed them in order by how structured the information is, with the most structured first.

  1. Set


    That will cause programs to print out additional information of the programmers’ choosing. You can use higher or lower numbers for more or less information. Most programs don’t use levels higher than 5.

  2. Print the code of procedures with showstat:


  3. Trace the execution of particular procedures with trace:


  4. Trace the execution of everything with printlevel:


    You can use higher or lower numbers for more or less information.

7 How to display a build in function code?


Or to see line numbers


Or can use the Browse(); command


Another option I found is


Then the above produces listing that can be copied as string with line wrapping ok.

8 How to build a LIST or a SET on the fly?

One way


But a better way is to use seq


9 How to make function display more information of what it is doing?

By Carol Devore on the net:

Use infolevel. 
For example, to show what logic dsolve uses, do this: 
 
First try 
> infolevel[all]:= 5; 
 
That will probably give more information than you want, but if not, 
then try 
> printlevel:= 1000; 
 
If you want information about a specific procedure, you can use debug. 
 For example, 
restart; 
debug(`int/int`); 
int(p, x= 0..1); 
 
To find out what procedures are being called without getting too much 
extra information, use excallgraph.

Trying on dsolve


10 How to solve a differential equation with initial conditions?

To solve \[ y''-3y'+2y=10 e^{5 x} \] with \(y(0)=1,y'(0)=5\) do


The above can also be written using D@@ notation, like this


11 How to verify that the ODE solution given is correct?

use odetest and check if it gives zero.


12 How to know the type of ODE?

Maple can classify the ODE.


To get help on this type of ODE, do


13 What packages to load for differential equations?

Use  with(DEtools);

14 How to plot solution of differential equations?


pict

To get a better plot, change the stepsize and independent variable range


pict

15 How to plot a function?

Here, I am looking at fouries series expansion of \(f(x)=0\) between \(–\pi \) and 0, and \(f(x)=1\) between 0 and \(\pi \).

The Fouries series expansion is worked out to be as below. This shows that the series approximate the above \(f(x)\) as more terms are added


pict

16 How to run maple from command line?

From DOS, point to where your cmaple is

>"C:\Program Files\Maple 7\BIN.WNT\"cmaple

To make it execute maple commands use the < foo.txt to pipe maple commands in the file to it.

17 How to use matrices in maple?


You can extract any part of the matrix like this:


\[ \left [ \begin {array}{c} 2\\ 6\\ 6\end {array} \right ] \]

By Carl Devore http://mathforum.org/kb/message.jspa?messageID=1570678

Maple list and sequence structures are more flexible than Matrices, which are 
highly structured.  A Maple list of lists (called a listlist in Maplese) is akin 
to a matrix in some other languages.  Many matrix 
operations can be performed directly on the listlist form, but to do 
serious linear algebra, you should convert to a Matrix.  Of course, it is 
trivial to convert a listlist to Matrix: 
 
LL:= [[1,2], [3,4]]; 
M:= Matrix(LL); 
 
So here is another solution in line with your original wishes.  This is 
"index free", but the table-based solution I gave earlier should be 
faster.  (It is usually considered bad form to repeatedly append to a list or sequence.) 
 
L:= [][]; # Create a NULL sequence 
do 
   line:= readline(file); 
   if line::string then 
      if line contains valid data then 
         Z:= a list of that data; 
         L:= L, Z 
      fi 
   else 
      break 
   fi 
od 
 
A:= Matrix([L]); # Note []: seq -> list.

To move move a column into a matrix: Here, I want to copy 2nd column to the 3rd column:

A; \[ \left [ \begin {array}{ccc} 1&2&3\\ 3&6&7\\ 5&6&9\\ 7&7&7 \end {array} \right ] \]

B:=A[1..row,2]; \[ \left [ \begin {array}{c} 2\\ 6\\ 6\\ 7 \end {array} \right ] \]

 A[1..row,3]:=B: A;

\[ \left [ \begin {array}{ccc} 1&2&2\\ 3&6&6\\ 5&6&6\\ 7&7&7 \end {array} \right ] \]

18 How can maple return more than value from a procedure call?

Maple can return multiple values. Make sure to use the comma "," in the body of the procedure to separate each return value. Example:


19 How does maple handle procedure arguments?

When passing a variable to maple procesure, the variable VALUE is passed to the procedure (This is different from say Fortran where the default is pass by reference). But this is the same as with Mathematica.

For example, if a variable X had value 10, then you call a procedure FOO passing it X, then inside FOO, X will be the number 10, not the argument variable X. So, this means one can not have X on the left hand side inside FOO. Like this x:=1

The only way to assign new value to the input and return new value, is to use a local variable, like this:


20 How to define your own data types?

Use `type/name` to define new type name.


21 How to find max element in a matrix and its position as same time?

Code from net by Carl Devore:


Code below from C W


22 How to create a package?

First create the module:


Gives 9, [3, 3]. Now save the module.


now save the library to disk.  savelib(nma);

Now we can test everything by reinitialize everything and reload the library.


Now to print a proc() in the package, do


Now you can list what packages exist in the archive:


Some notes. need to clean later


Also there is a long thread here on Maple prime on making personal packages in Maple How-To-Create-A-Personal-Package

23 How to convert from floating point to Hex?

From: Robert Israel (israel@math.ubc.ca) 
Subject: Re: Getting non-integral results in hex 
Newsgroups: comp.soft-sys.math.maple 
Date: 2003-06-13 00:07:37 PST 
 
I assume you mean floating-point numbers.  Note that 
Maple floats (as opposed to "hardware floats") are 
in fact stored in base 10.  To convert a float to hex 
with n digits after the ".", you can use this: 
 
> `convert/hexfloat`:= proc(x::numeric, n::nonnegint) 
  local A,B,ax,R; 
  if nargs = 1 then return procname(x,round(Digits*log[16](10))) fi; 
  if x = 0 then return cat(`0.`,`0`$n) fi; 
  ax:= abs(x); 
  A:= floor(ax); 
  B:= round(frac(ax)*16^n); 
  if B = 16^n then A:= A+1; B:= 0 fi; 
  R:= cat(convert(A,hex),`.`); 
  if x < 0 then R:= cat(`-`,R) fi; 
  cat(R,substring(convert(16^n+B,hex),2..-1)); 
  end; 
 
And then, e.g.: 
 
> convert(1234.5678, hexfloat, 4); 
 
                               4D2.915B

24 How to find taylor series expansion of functions?

mtaylor(sin(x),[x],10);

\[ x-1/6\,{x}^{3}+{\frac {{x}^{5}}{120}}-{\frac {{x}^{7}}{5040}}+{\frac { {x}^{9}}{362880}} \]

25 How to print elements of a matrix?


26 How to find determinant of matrix?


27 How to generate Hilber matrix?

H := LinearAlgebra:-HilbertMatrix(5);

\[ \left [ \begin {array}{ccccc} 1&1/2&1/3&1/4&1/5\\ \noalign {\medskip }1/ 2&1/3&1/4&1/5&1/6\\ \noalign {\medskip }1/3&1/4&1/5&1/6&1/7 \\ \noalign {\medskip }1/4&1/5&1/6&1/7&1/8\\ \noalign {\medskip }1/5&1/6&1 /7&1/8&1/9\end {array} \right ] \]

28 How to plot matrix data?

Matlab is much easier here. In maple, need to covert the matrix to a list of list of points first.


pict

29 How to catch an error from a proc()?

An error in maple raises an exception. So, use try catch to trap it as follows:


30 How to convert 3456 to 3,456 ?

From the net, by Carl Devor:


To convert a string to array of chars use array(StringTools:-Explode(S))


Now can use the string as normal array


31 How to use units ?


32 On High precision. Using taylor to solve ODE

From: Robert Israel (israel@math.ubc.ca) 
Subject: Re: given precision in Maple 
Newsgroups: comp.soft-sys.math.maple 
Date: 2003-07-16 20:19:06 PST 
 
Set Digits:= n and all calculations from this point will be done with n 
digits.  Mathematical functions will be correct to n digits as well (to 
the extent this is practical). 
 
If you want high-accuracy numerical ODE solutions, on the other hand, 
it's not so simple.  I think the best way is using the taylorseries 
method.  For example, consider the problem y' = y^2, y(1) = 1, where 
the exact solution y = 1/(2-x) has y(1.9) = 10. 
 
> Digits:= 30: 
  sol:= dsolve({D(y)(x)=y(x)^2, y(1) = 1}, y(x), numeric, 
            method=taylorseries, abserr=1e-25): 
  sol(1.9); 
 
          [x = 1.9, y(x) = 9.99999999999999999999999797691] 
 
> 10 - eval(y(x),%); 
 
                                       -23 
                            0.202309 10 
 
The other methods (in particular the default rkf45) do not give results 
anywhere near this good.

33 How to evaluate catlan number and other sums?

Use the Sum command.


Notice, if I used the sum command instead of the Sum command I get this result:


34 How to write a text file that contains a package, and load it and execute it?

This shows how to do a simple package and use it without building a library. Just using a plain text file.

Create this nma_pkg1.txt file:


now save it, and from maple do


now execute f1() as this:


now put it in a library (so that we can use with, instead of read)


now make changes to the nma_pkg1.txt file and updated again as above.

35 How to find what packages are included in maple

?index,package

36 How to plot the gradiant vector field?


pict

or

or can do it in just one command: plots[gradplot](f,x=-2..2,y=-2..2);

37 How to put the digits of Pi into a list?

Suppose you want the 100 digits of Pi put in a list. This is one way to do it:


This below now tells how many times each digits occurs.


38 Digits of PI in maple and mma

Written sometime in 2005? I should really record the time when I write something.

I just run these now, Auust 2014, and now Maple 18 as very fast. So this all below is no longer valid. I will leave it here for now for reference until I update it all later

I have written a few lines of code, which counts how many times each digit occurs after the decimal points of \(\pi \)

Written this in maple first. Then did similar thin in mma 5.0. Both are run on the same PC. No other applications are running at the time when I run the code.

The basic idea of the algorithm is to use evalf(Pi,digits) in maple to find \(\pi \) for any number of decimal digits, and to use N[Pi,digits] in mma for doing the same. (Where the variable digits above is the number of digits)

Then in maple convert the above \(\pi \) to a string, and generate a sequence of the characters to right of decimal point, then use stats[transform,tally] to do the actual counting.

In mma, I use RealDigits[] to get a list of the digits, and then use Count[] to do the counting.

This is result of some of the runs to find Pi to some digits, and the total time (to find Pi and do the counting)

All times are in cpu seconds, machine is P4, 2.8 Ghz, 500 MB of RAM, single CPU, hyperthreading enabled, running XP home edition. Maple 9.03 student version, and mma 5.0 student version.

Below is the result, and below that I show the maple code and the mma code.

Because of this, before each run in mma, I exited the application and started it fresh. In maple, it does not matter for the above reason.

100,000 digits: 
             Find_Pi     Total 
Maple 9.0      55          84 
Mma 5.0        0.9         1.54

Mma is 60 times faster in finding pi and about 56 times faster overall

300,000 digits: 
             Find_Pi     Total 
Maple 9.0     309         781 
Mma 5.0       3.7         6

Mma is 300 times faster in finding Pi, and 130 times faster overall.

3,000,000 digits 
             Find_Pi     Total 
Maple 9.0 
Mma 5.0        85        118 
 
Maple time in hours ! Still running.

Maple code


mma code


update 12/25/03 Changed maple code on how to do the counting : To use


Now the counting in maple is much faster. It is always hard to know which is the best function to use.


39 How to find where functions are?

From: Ken Lin (maplemath@tp.edu.tw) 
Subject: Re: how to find which package a function belongs to? 
Newsgroups: comp.soft-sys.math.maple 
Date: 2003-12-04 03:49:26 PST 
 
When Maple first loaded, There are only two kinds of "internal" 
commands which can be called directly. One is the "kernal" commands 
coded in C, and the other includes many "internal" prodecures 
programmed by the kernal commands which lies in the "Main Library", 
There are also many other "external" procedures which were categorized 
into so called "packages", plots[display](...) for example, plots[] is 
a package(Library), and display() is the prodecure inside plots[]. All 
the packages can be loaded by with() command, like 
> with(plots); 
 
 
Because Different Packages include user library might have the same 
procedure name, Maple doesn't realize the "procedure_name" you type 
in, it took it for a "symbol". If you really want to know which 
packages provided by Maple the external procedure lies in, just mark 
the procedure_name and press F1 key, the Maple Help Browser will show 
you the packages you might be interested. 
 
By the way, plot3d() is a "internal" procedure lies in the Main 
Library. You can confirm that by: 
> op(0, eval(plot3d)); 
                         procedure 
or in Maple 9 
> type( plot3d, 'std' );      #Is it internal?                      true 
> type( plot3d, 'stdlib' );   #Does is lie in "Standard(Main) Library"? 
                         true 
If you are interested the codes inside plot3d()... 
> interface(verboseproc=2):   #Turn on verboseproc 
> print(plot3d);              #eval() also works 
> interface(verboseproc=1):   #Turn off verboseproc 
 
I hope this will give you some help. Have fun with Maple. 
 
Ken Lin

40 on maple data types

See http://www.maplesoft.com/applications/view.aspx?SID=1533&view=html&L=G

41 how to extract stuff from a list based on some selection?

use select. For example


42 how to test if all elements of a matrix are integers?


I am sure there is a better way than the above. Need to find out.

43 how to use laplace transform?


\[ {\frac {\omega }{{\omega }^{2}+{s}^{2}}} \]

To find the inverse, do:


\[ \sin \left (\omega \,t \right ) \]

44 questions I have


45 3D plotting


pict

46 How to raise each element in a list to a power?

Use map


47 How to generate a sequence with any increment?


48 What shortcuts are there for matrix manipulation?

read ?MVshortcut, ?MVassignment, and ?Mvextract and Transpose(R) can be shortened to R^%T

49 How to solve a set of equations for the derivative?

Written feb 20, 2004

This is problem 7.4 chapter 4, in the Mary Boas book. Given \begin {align*} x s^2+y t^2 &= 1\\ x^2 s+y^2 t &= xy-4 \end {align*}

Find \(\frac {dx}{dt}, \frac {dx}{ds}, \frac {dy}{dt}, \frac {dy}{ds}\) at \(x=1,y=-3,s=2,t=-1\)

This is how I did it in maple:


\begin {align*} {\frac {\partial }{\partial s}}x \left (s,t \right ) &= -{\frac {x \left (s,t \right ) \left (x \left (s,t \right ) {t}^{2}-4\,y \left (s,t \right ) st+2\,x \left (s,t \right ) s \right ) }{2\,x \left (s,t \right ) s{t}^{2}-2\,y \left (s,t \right ) t{s}^{2}+x \left (s,t \right ) {s}^{2}-y \left (s,t \right ) {t}^{2}}}\\ {\frac {\partial }{\partial t}}x \left (s,t \right ) &=-{\frac {y \left (s,t \right ) t \left (-3\,y \left (s,t \right ) t+2\,x \left (s,t \right ) \right ) }{2\,x \left (s,t \right ) s{t}^{2}-2\,y \left (s,t \right ) t{ s}^{2}+x \left (s,t \right ) {s}^{2}-y \left (s,t \right ) {t}^{2}}}\\ {\frac {\partial }{\partial s}}y \left (s,t \right ) &=-{\frac {x \left ( s,t \right ) \left (3\,x \left (s,t \right ) s-2\,y \left (s,t \right ) \right ) s}{2\,x \left (s,t \right ) s{t}^{2}-2\,y \left (s,t \right ) t {s}^{2}+x \left (s,t \right ) {s}^{2}-y \left (s,t \right ) {t}^{2}}}\\ {\frac {\partial }{\partial t}}y \left (s,t \right ) &=-{\frac {y \left ( s,t \right ) \left (4\,x \left (s,t \right ) st-y \left (s,t \right ) {s }^{2}-2\,y \left (s,t \right ) t \right ) }{2\,x \left (s,t \right ) s{t} ^{2}-2\,y \left (s,t \right ) t{s}^{2}+x \left (s,t \right ) {s}^{2}-y \left (s,t \right ) {t}^{2}}} \end {align*}


50 How to solve a set of equations for differentials?

This is problem 7.15 chapter 4 in Boas:

Given \(x^2 u-y^2 v=1\) and \(x+y=uv\) Find \(\frac {dx}{du},v\) and \(\frac {dx}{du},y\)

This is the maple code to solve this:


pict

51 How to plot binary tree

by http://www.math.fsu.edu/~bellenot


pict

52 solving problem 12.4 chapter 4, Math 121A, Boas book. using maple


\[ -{\frac {\sin \relax (x ) \sin \left (\cos \relax (x ) \right ) }{\cos \relax (x ) }}-{\frac {\cos \relax (x ) \sin \left (\sin \relax (x ) \right ) }{\sin \relax (x ) }} \]

53 example of doing convergence test in maple


pict

54 Solving problem math 121A, ch 14, 3.18, Boas book. contour integration


\[ \frac {-1}{3} \]

55 How to find multiple roots to an equation such as \(sin(x) = 0\)


Pi _Z1~

56 Dr Basti Associated Legendre

Subject:      Associated Legendre 
Author:       Mehran Basti <Basti@worldnet.att.net> 
Organization: AT&T Worldnet 
Date:         Mon, 25 Nov 2002 02:48:15 GMT

Dear newsgroup:

I had mentioned that my methods will solve classical equations without the use of infinite series.

The following is a Maple code of my old files. Those days I had Maple2 but the general idea is the same in the process and you see that we can also solve the integrals involved.

It does not make sense how are the theory behind it but eventually it will come into light.

Just read the procedures and you can see the solution of associated legendre AL at the end.

> s1:=-diff(p(t),t)+p(t)^2; 
> 
> s2:=exp(2*int(p(t),t))*T(t); 
> s3:=s1+s2; 
> s4:=diff(T(t),t)/T(t); 
> s5:=-(1/2)*(diff(s4,t))+(1/4)*s4^2; 
> s6:=s5+s2; 
> p(t):=-1/t+(1)/(2-t); 
> s1:=simplify(s1); 
> s1:=collect(%,t); 
> s2:=simplify(s2); 
> s1+s2=(2*t^2-4*t+m^2-1)/(t*(-2+t))^2; 
> solve(%,T(t)); 
> T(t):=simplify(%); 
> s2:=simplify(s2); 
> s2+s1; 
> s3:=simplify(%); 
> 
> s6:=simplify(s6); 
> t*(-2+t); 
> simplify(%); 
> z:=(r3*t^3+r2*t^2+r1*t+r0)/(%); 
> 
> simplify(diff(z,t)+z^2-s6); 
> s7:=collect(numer(%),t); 
> 
> coeff(%,t,0); 
> solve(%,r0); 
> r0:=op(1,{%}); 
> coeff(s7,t,1); 
> solve(%,r1); 
> r1:=simplify(%); 
> coeff(s7,t,2); 
> solve(%,r2); 
> r2:=simplify(%); 
> coeff(s7,t,3); 
> solve(%,r3); 
> r3:=simplify(%); 
> simplify(s7); 
> s3:=simplify(s3); 
> s4:=simplify(s4); 
> s6:=simplify(s6); 
> T(t):=simplify(T(t)); 
> z:=simplify(z); 
> 1/2*s4+2*p(t)+z; 
> s8:=simplify(%); 
> exp(int(%,t)); 
> expand(%); 
> g:=(%); 
> simplify(g,power); 
> g:=%; 
> Int(%,t); 
> Integralg:=(%); 
> int(g1(t),t); 
> x1:=-p(t)+g1(t)/(%); 
> diff(x1,t)+x1^2-s3; 
> simplify(%); 
> s10:=numer(%); 
> solve(%,int(g1(t),t)); 
> Ing:=(%); 
> simplify(subs(g1(t)=g,%)); 
> 
>  Ing:=(%); 
> expand(%); 
> Ing:=simplify(%); 
> simplify(diff(%,t)-g); 
> expand(%); 
> simplify(%); 
> x:=-p(t)+g/Ing; 
> simplify(diff(x,t)+x^2-s3); 
>  int(x,t); 
> exp(%); 
> expand(%); 
> s11:=simplify(%); 
> ALT:=t*(2-t)*diff(u(t),t$2)+2*(1-t)*diff(u(t),t)+(2-m^2/(1-(1-t)^2))*u(t); 
> -2*(1-t)/(2*t*(2-t)); 
> int(%,t); 
> exp(%); 
> s12:=simplify(%,power); 
> 
> u1:=s12*s11; 
> u1:=simplify(%,power); 
>  simplify(subs(u(t)=u1,ALT)); 
> AL:=(1-nu^2)*diff(u(nu),nu$2)-2*nu*diff(u(nu),nu)+(2-m^2/(1-nu^2))*u(nu); 
> 
> u2:=subs(t=1-nu,u1); 
> simplify(subs(u(nu)=u2,AL)); 
>

The advantage of these methods are that there are ample rooms for advances.

Today my skills for solving classical equations such as Riccati is much advanced.

Highly complicated and more general Riccati equations in its billions now possible.

Sincerely

Dr.M.Basti

57 Understanding conformal mapping in maple

To plot mapping of complex function in maple, use [plots]conformal The trick is to how to specify the quadrant in the x-y plane. This example shows how.

Suppose we want to map the first quadrent. Then we specify the DIAGONAL points in the range, from the lower left corner to the upper right corner, which then should be 0..1+I Because 0 is the lower left corner, and \((1,i)\) is the upper right corner. Example:


pict

This below uses the first TWO quadents, i.e. the upper half of the x-y plane


pict

This below puts the plots next to each others so to see them


pict

58 Is there a way to keep the assumptions but not see the tilda character show up?

interface(showassumed=0) removes all tildas and interface(showassumed=1) adds the tildas.

59 Fourier series in maple

I wrote this to generate FS in Maple for some HW I was doing. I think this was for Math 121A at UC Berkeley in 2003


pict

To animate do


Here is the animation from the Maple notebook:

some text

Another version


pict

60 How to plot graphs next to each others in a grid like fashion


pict

61 How to generate Pi on X-axis

From book Maple animation by John Putz


pict

62 How to make output from FunctionAdvisor look better?

From Preben Alsholm


or answer by Thomas Richard


63 How to do partial fractions?

Use convert(expr,parfrac) or convert(f,fullparfrac)

64 How to generate sequence sum symbolically


\[ a_{{1}}b_{{1}}+a_{{2}}b_{{2}}+a_{{3}}b_{{3}}+a_{{4}}b_{{4}}+a_{{5}}b_{ {5}}+a_{{6}}b_{{6}}+a_{{7}}b_{{7}} \]

65 Nice plot from Maple

from Serge from the net:


pict

66 How to check if 2 expressions are the same?

Use evalb(). For example evalb(I*sinh(x)=sin(I*x)); gives true

The above does not always work. Only sure way is to do this


67 converting series to factorials

Function by Robert Israel from the net:


\[ \text {series} \left (x-{\frac {{x}^{3}}{ \left (\relax (3 ) \right ) !}}+{\frac {{x}^{5}}{ \left (\relax (5 ) \right ) !}}+O \left ({x}^{7} \right ) ,x,7 \right ) \]

68 How to find what new additions made to Maple?

 ?updates,maple10

69 Maple can’t solve laplace equation and numerically

Maple 2020.


Compare to


\[ u \left (x,y \right ) =\sum _{n=1}^{\infty }-200\,{\frac { \left ( \left (-1 \right ) ^{n}-1 \right ) {{\rm e}^{10\,\pi \,n}}\sin \left (1/10\,n\pi \,x \right ) \left ({{\rm e}^{1/10\,n\pi \,y}}- {{\rm e}^{-1/10\,n\pi \,y}} \right ) }{\pi \,n \left ({{\rm e}^{20\,\pi \,n}}-1 \right ) } } \]

70 Some Maple Matrix operations

Create a new matrix, by appending some rows of one matrix to rows from another matrix:


\[ \left [ \begin {array}{ccc} 1&2&3\\ \noalign {\medskip }4&5&6 \end {array} \right ] \]


\[ \left [ \begin {array}{ccc} 7&8&10\\ \noalign {\medskip }11&12&13 \\ \noalign {\medskip }14&15&16\end {array} \right ] \]

Now append first row of A to last 2 rows of B


\[ \left [ \begin {array}{ccc} 1&2&3\\ \noalign {\medskip }11&12&13 \\ \noalign {\medskip }14&15&16\end {array} \right ] \]


\[ \left [ \begin {array}{cccc} 1&7&8&10\\ \noalign {\medskip }4&11&12&13 \end {array} \right ] \]


\[ \left [ \begin {array}{ccc} 7&8&10\\ \noalign {\medskip }14&15&16 \end {array} \right ] \]


\[ B:=\left [ \begin {array}{ccc} 0&99&92\\ \noalign {\medskip }8&0&-31 \\ \noalign {\medskip }69&44&0\end {array} \right ] \] \[ \left [ \begin {array}{ccc} 0&99&92\\ \noalign {\medskip }8&0&-31 \\ \noalign {\medskip }69&44&0\end {array} \right ] \] To find inverse.


\[ \left [ \begin {array}{cc} 1/2&0\\ \noalign {\medskip }-1&1/2 \end {array} \right ] \]

To check that for any matrix A, then A*transpose(A) is always a matrix which is symmetrical


\[ A:=\left [ \begin {array}{ccc} 99&44&-31\\ \noalign {\medskip }29&92&67 \end {array} \right ] \]

\[ \left [ \begin {array}{ccc} 99&44&-31\\ \noalign {\medskip }29&92&67 \end {array} \right ] \]

how to create a random lower triangular matrix?


\[ \left [ \begin {array}{cccc} 67&0&0&0\\ \noalign {\medskip }-31&92&0&0 \\ \noalign {\medskip }44&29&99&0\\ \noalign {\medskip }69&8&27&-4 \end {array} \right ] \]

71 How set diagonal elements to some value, say 1?


\[ A:= \left [ \begin {array}{ccccc} 1&-98&-76&-4&29\\ \noalign {\medskip }-38& 1&-72&27&44\\ \noalign {\medskip }-18&57&1&8&92\\ \noalign {\medskip }87& 27&-32&1&-31\\ \noalign {\medskip }33&-93&-74&99&1\end {array} \right ] \] \[ \left [ \begin {array}{ccccc} 1&-98&-76&-4&29\\ \noalign {\medskip }-38& 1&-72&27&44\\ \noalign {\medskip }-18&57&1&8&92\\ \noalign {\medskip }87& 27&-32&1&-31\\ \noalign {\medskip }33&-93&-74&99&1\end {array} \right ] \]

72 How to multiply roots of a polynomial?


Gives

pict

73 How to plot a surface in 3D?


pict

One can also use impliticplot3d


pict

74 How to convert trigs to sinc function in an expression

From http://www.mapleprimes.com/questions/40470-Trigonometric-Function-To-Sinc-Function

Maple doesn’t have a sinc function. If you mean the function sinc(x) = sin(x)/x, you could say something like


75 How to find NullSpace and ColumnSpace of a matrix?


pict

76 How to fix the interface to using Maple notation for input?

Go to tools->optiopn, and Display, and select Maple notation for input display.

77 How to find all solutions using allvalues ?


78 How to add one to only the elements of the diagonal of a matrix?

Use Map with filter


79 How to search help for updates on some package

Go to http://www.maplesoft.com/support/help/search.aspx

and type say updates,Maple17,DE in the small box there.

80 How to work with groups in worksheet

From http://www.mapleprimes.com/questions/201092-How-To-Insert-New-Paragraph-On-Its-Own by Carl Love:

I use these special keystrokes constantly in my Maple worksheet typing: 
 
    Ctrl-J: Insert execution group below cursor. 
    Ctrl-K: Insert execution group above cursor. 
    Ctrl-T: Switch from executable code mode to text mode (for entering extended formatted comments). 
    Ctrl-M: Switch from text mode to executable code mode. 
    Shift-Enter (or Shift-Return): Begin a new line in the same execution group. 
    Func-3: Split execution group into two (at cursor). 
    Func-4: Join cursor execution group with execution group below.

81 How to read code into worksheet?

Use the read command, as in read "mycode.mpl" where mycode.mpl is plain text file that contains maple code

82 Code editors for Maple

  1. http://www.mapleprimes.com/forum/codeeditormaple

  2. http://www.mapleprimes.com/blog/joe-riel/emacs-mode-for-maple

  3. http://www.mapleprimes.com/blog/jacquesc/vim-mode-for-maple

  4. http://www.maplesoft.com/products/toolboxes/IDE/index.aspx

83 How to find if package is module or table?

New packages are module, which allows using packageName:-function() since it is easier. Old packages use tables which needs packageName[function]() which is not common.

To find if package is based on module or not, use the command


This will return true or false. To know if name is package use the command


84 How to replace a string?


85 How to use geometry and plottools ?


To know more about the intersection, use this:


86 How to simplify log expressions ?

Use symbolic option


87 How to simplify hyperbolic expression ?

How to convert \[ \frac {3+2\sinh (x)^2}{\sinh (x)^2\tanh (x)} \] to \[ 3 \coth ^3(x)-\coth (x) \]


88 How to create text file and append string to it?


89 How to search packages and libraries?

To find in which library a command is do


To get content of library do


Then can use this to print the name of each symbol/command, and then use whattype command to find its type


To get list of Maple kernel builtin commands and symbols, use this. Written by Acer from Maple prime site:


The above gives on Maple 18.02 the following

["crinterp", "equation", "`{}`", "even", "debugopts", 
  "embedded_imaginary", "define_external", "embedded_real", 
  "coeff", "cx_zero", "coeffs", "embedded_axis", "conjugate", 
  "constant", "convert", "cx_infinity", "dlclose", "identical", 
  "divide", "hfloat", "`done`", "function", "`$`", "fraction", 
  "denom", "float", "degree", "finite", "disassemble", 
  "extended_rational", "diff", "extended_numeric", "frem", 
  "`union`", "frontend", "upperbound", "exports", "writeto", 
  "factorial", "`xor`", "evalgf1", "type", "expand", "typematch", 
  "entries", "unames", "evalb", "unbind", 
  "`evalf/hypergeom/kernel`", "atomic", "hfarray", "anything", 
  "hastype", "complex", "has", "boolean", "goto", "`:-`", 
  "gmp_isprime", "`!`", "genpoly", "anyfunc", "gc", "algebraic", 
  "SFloatMantissa", "ssystem", "Scale10", "`stop`", "Scale2", 
  "sort", "SearchText", "`[]`", "`~`", "`subset`", "~Array", 
  "subsindets", "~Matrix", "streamcall", "~Vector", "subs", 
  "Unordered", "table", "ToInert", "system", 
  "_hackwareToPointer", "substring", "UpdateSource", "subsop", 
  "_maplet", "trunc", "_jvm", "`kernel/transpose`", "_treeMatch", 
  "tcoeff", "_savelib", "taylor", "abs", "rtable_num_dims", 
  "addressof", "rtable_num_elems", "_unify", "rtable_options", 
  "_xml", "rtable_redim", "`and`", "rtable_scale", "andmap", 
  "rtable_scanblock", "alias", "rtable_size", "anames", 
  "rtable_sort_indices", "assign", "savelib", "assemble", 
  "rtable_zip", "array", "select", "appendto", "searchtext", 
  "cat", "series", "callback", "selectremove", "bind", "sign", 
  "attributes", "setattribute", "ormap", "ArrayOptions", "order", 
  "Array", "parse", "`**`", "overload", "`*`", "`::`", "numer", 
  "CopySign", "numelems", "`^`", "`or`", "`||`", "op", "nops", 
  "seq", "normal", "time", "`not`", "piecewise", "numboccur", 
  "`?[]`", "userinfo", "modp2", "inner", "mods", "timelimit", 
  "mvMultiply", "traperror", "negate", "rtable_normalize_index", 
  "call_external", "rtable_is_zero", "assigned", "rtable_indfns", 
  "evalf", "rtable_histogram", "eval", "evaln", "rtable_eval", 
  "truefalse", "evalhf", "rtable_convolution", "tabular", "mul", 
  "rtableInfo", "zppoly", "`if`", "rtable", "uneval", "remove", 
  "sfloat", "rhs", "specfunc", "readlib", "string", "reduce_opr", 
  "symbol", "ASSERT", "`?()`", "realcons", "TRACE", "`quit`", 
  "relation", "_local", "pointto", "sequential", "add", "print", 
  "set", "SFloatExponent", "iolib", "radical", "SDMPolynom", 
  "`int/series`", "protected", "Record", "irem", "procedure", 
  "Re", "iquo", "poszero", "isqrt", "real_infinity", "RETURN", 
  "is_gmp", "ratpoly", "`+`", "lcoeff", "rational", "OrderedNE", 
  "kernelopts", "range", "Object", "NumericEventHandler", 
  "icontent", "numeric", "NumericStatus", "igcd", "odd", 
  "NumericClass", "ilog10", "nonpositive", "NumericEvent", 
  "ilog2", "nonreal", "`implies`", "posint", "NameSpace", 
  "indets", "positive", "NextAfter", "indices", "polynom", 
  "MPFloat", "`intersect`", "pos_infinity", "MorrBrilCull", 
  "`<`", "member", "neg_infinity", "Im", "maxnorm", "name", 
  "`<>`", "max", "negint", "`<=`", "map2", "negative", "modp1", 
  "nonnegative", "FromInert", "modp", "negzero", 
  "EqualStructure", "`minus`", "nonposint", "`>=`", "min", 
  "nonnegint", "`>`", "DefaultUnderflow", "lexorder", 
  "imaginary", "`=`", "lhs", "indexable", "ERROR", "ldegree", 
  "indexed", "EqualEntries", "length", "integer", "macro", 
  "list", "DEBUG", "map", "literal", "`..`", "lowerbound", 
  "`module`", "Default0", "lprint", "moduledefinition", 
  "DefaultOverflow"] 
                              296 

90 How to numerically solve a BVP ode and plot the solution?

This one has one solution


This solved coupled ODE’s, so there are 2 solutions. Say \(x_1(t)\) and \(x_2(r)\), It is a little tricky to plot all solutions generated, but here is an example


And now to plot do


91 How to find the indicial equation for an ODE?

For say Bessel ode of order zero:


The third argument above is the singularity point of interest. So we have two roots, both zero. These are now used for finding the power series solution \(y(x)\) if needed.

Another example, is Bessel of order 1


92 How to display on screen for specific width?

This below by Axel Vogt posted on sci.math.symbolic which does a nice job of formatting output to specific width.


93 Maple IDE links

for VIM

  1. https: //code.google.com/p/maplevim/source/browse/trunk/syntax/maple.vim

in vim, type set syntax=maple after putting the file maple.vim in ~/.vim/syntax/maple.vim. I found maple.vim in above link.

For Maple IDE

MapleIDE18

94 loading, remove and finding what packages loaded

use packages(); to find what packages loaded. use unwith to remove package


95 some rules of thumbs when using Maple

  1. put restart in separate execution group

  2. do not use with inside proc(). Use uses instead.

96 How to write derivative

To write \(y'(x)=x\), one way is diff(y(x),x)=x and another is D(y)(x)=x. To write \(y''(x)=x\), one way is diff(y(x),x$2)=x and another is (D@@2)(y)(x)=x.

To convert from one form to another use convert(eq,diff) or convert(eq,D)

97 How to solve heat PDE in 1D in Maple 2017?

to solve \(\frac {\partial u(x,t)}{\partial t}=k \frac {\partial ^2 u(x,t)}{\partial x^2}\) with homogeneous dirichlet boundary conditions \(u(0,t)=0,u(L,t)=0\) the commands are


Which gives

\[ u \left (x,t \right ) =\sum _{{\it \_Z1}=1}^{\infty }{\it \_C1} \left ({\it \_Z1} \right ) \sin \left ({\frac {\pi \,{\it \_Z1}\,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{{\it \_Z1}}^{2}t}{{L}^{2}}}}} \]

Which can be made more readable as follows


\[ u \left (x,t \right ) =\sum _{n=1}^{\infty }{\it \_C1} \relax (n ) \sin \left (x\lambda \relax (n ) \right ) {{\rm e}^{-kt \left (\lambda \relax (n ) \right ) ^{2}}} \]

For homogeneous Neumann B.C., at \(x=0\), let \(\frac {\partial u}{\partial x}=0\) and at \(x=L\) let \(u(L,t)=0\), the solution it gives looks different than my hand solution


It gives

\[ u \left (x,t \right ) ={\it \_C3}\,{\it \_C2}\, \left ({{\rm e}^{1/4\,{\frac {2\,i\pi \,xL-k{\pi }^{2}t}{{L}^{2}}}}}+{{\rm e}^{-1/4\,{\frac {\pi \, \left (2\,ixL+k\pi \,t \right ) }{{L}^{2}}}}} \right ) \]

I need to look more into the above and see if this comes out to be the same as my hand solution.

Another example, with initial conditions now given


The result is

\[ u \left (x,t \right ) =\sum _{n=1}^{\infty } \left (2\,{\frac {1}{L}{{\rm e}^{-1/4\,{\frac {k{\pi }^{2}t \left (1+2\,n \right ) ^{2}}{{L}^{2}}}}}\cos \left (1/2\,{\frac {\pi \,x \left (1+2\,n \right ) }{L}} \right ) \int _{0}^{L}f \relax (x ) \cos \left (1/2\,{\frac {\pi \,x \left (1+2\,n \right ) }{L}} \right ) \,{\rm d}x} \right ) \]

Another example


\[ u \left (x,t \right ) =\sum _{n=1}^{\infty }768\,{\frac {1}{\pi \, \left (16\,{n}^{4}+32\,{n}^{3}-136\,{n}^{2}-152\,n+105 \right ) }{{\rm e}^{-1/4\,{\frac {k{\pi }^{2}t \left (1+2\,n \right ) ^{2}}{{L}^{2}}}}}\cos \left (1/2\,{\frac {\pi \,x \left (1+2\,n \right ) }{L}} \right ) } \]

Another example


\[ u \left (x,t \right ) =\sin \left ({\frac {\pi \,x}{L}} \right ) {{\rm e}^{-9\,{\frac {{\pi }^{2}kt}{{L}^{2}}}}} \left (-2\,\cos \left (2\,{\frac {\pi \,x}{L}} \right ) +3\,{{\rm e}^{8\,{\frac {{\pi }^{2}kt}{{L}^{2}}}}}-1 \right ) \]

The above answer seems wrong. There is not even a summation in it. It is different from my hand solution. Look more into it.

98 How to make multiple assumptions on a symbol?


Now can use is(A,constant);

99 How to make Maple display diff(y(x),x) as \(y'(x)\) or as \(y'\) ?

Add this


The above will display the expression as \(y'(x)\). To make it now show the \(x\) do


Now it will show the expression as just \(y'\). For all the above to work, make sure you have Typesetting level set to Extended in the GUI.

This is done inside Tools->Options->Display menu.

To clear all the above Typesetting, do restart or do Typesetting:-Unsuppress(y(x))

100 How to check if expression is an equation?

check for ‘=‘ as follows


101 How to check if expression is a set?

check for ‘set‘ as follows


102 How to set boundary conditions for dsolve or pdsolve?

The Maple syntax for seeting initial and boundary conditions is very confusing, as compared to Mathematica, which seems to me to be simpler. So I wrote this to remind me of the syntax each time.

For PDE, assuming dependent variable is \(u(x,t)\) then



Conditions Maple code


\(u(0,t)=0\)  u(0,t)=0


\(\frac {\partial u}{\partial x}=0\) at \(x=0\) D[1](u)(0,t)=0


\(\frac {\partial ^2 u}{\partial x^2}=0\) at \(x=0\) D[1,1](u)(0,t)=0


\(\frac {\partial ^3 u}{\partial x^3}=0\) at \(x=0\) D[1,1,1](u)(0,t)=0


\(\frac {\partial u}{\partial t}=0\) at \(t=0\) D[2](u)(x,0)=0


\(\frac {\partial ^2 u}{\partial t^2}=0\) at \(t=0\) D[2,2](u)(x,0)=0


\(\frac {\partial ^3 u}{\partial t^3}=0\) at \(t=0\) D[2,2,2](u)(x,0)=0


Notice the syntax for the last one above. It is (D[1]@@2)(u)(0,t)=0 and not (D@@2)[1](u)(0,t)=0

For an ODE, assuming dependent variable is \(y(x)\) then the syntax is



Conditions Maple code


\(y(0)=0\)  y(0)=0


\(\frac {dy}{dx}=0\) at \(x=0\) D(y)(0)=0


\(\frac {d^2 y}{d x^2}=0\) at \(x=0\) (D@@2)(y)(0)=0


103 How to export a plot to PDF?

I could only find a way to export to eps


Make sure not to put : at the end of the plot command! else it will not be exported. It has to end with ;

This will same it to t.eps in the currentdir() location. Then used ps2pdf t.eps t.pdf to convert it to PDF. Or just ps2pdf t.eps it will automatically create t.pdf

Or ps2pdf -dCompatibilityLevel=1.4  t.eps but may it is best to do

ps2pdf -dCompatibilityLevel=1.4 -dEmbedAllFonts=true  t.eps

Also try adding

-dPDFSETTINGS=/printer

to the above. This tells it to optimize it for printing.

Another example of a direction field for an ODE


104 How to find all roots of complex number

To find roots of \( (3+4 i)^{1/3}\), do


105 How to convert matrix of matrices to a matrix?


Which gives

\[ \left [ \begin {array}{cc} \left [ \begin {array}{cc} 0&0 \\ \noalign {\medskip }0&0\end {array} \right ] & \left [ \begin {array} {cc} 0&0\\ \noalign {\medskip }0&0\end {array} \right ] \\ \noalign {\medskip } \left [ \begin {array}{cc} 0&0 \\ \noalign {\medskip }0&0\end {array} \right ] & \left [ \begin {array} {cc} 2&0\\ \noalign {\medskip }0&2\end {array} \right ] \end {array} \right ] \]

now


Gives

\[ \left [ \begin {array}{cccc} 0&0&0&0\\ \noalign {\medskip }0&0&0&0 \\ \noalign {\medskip }0&0&2&0\\ \noalign {\medskip }0&0&0&2\end {array} \right ] \]

106 How to do pattern matching in Maple?

Maple has a simple but easy to use pattern matching, which works well. Here are some example. For each case, will show what pattern to detect and how to do it. I am still not very good at pattern matching in Maple and will need to make improvement in this with time.

106.1 Example 1

Detect \(\sqrt (x y)\) in expression.


But if the expression was \(\sin (x)\sqrt {x y}+3\) then the above would fail, because there are a term after \(\sqrt {x y}\), so the pattern has to change to


107 How to find trig indetities?

use trigsubs, very useful command. For example


Gives

\[ [1/2\,\cos \left (\theta \right ) +1/2\,\cos \left (2\,\theta \right ) \cos \left (\theta \right ) ,1/4\,\cos \left (3\,\theta \right ) +3/4\,\cos \left (\theta \right ) ] \]

108 How to find directional derivative of scalar function?

Given \(f(x,y,z)=x^2 z+y^3 z^2-xyz\) we want to find its directional derivative along the vector \(n\).

One way


Gives

\[ -{\frac { \left (2\,xz-yz \right ) \sqrt {10}}{10}}+{\frac { \left (6\,{y}^{3}z+3\,{x}^{2}-3\,xy \right ) \sqrt {10}}{10}} \]

Another is


Gives the same result.

109 How to check if name is assigned a value?

For simple variable, use assigned


For a field in table do


For field in Record, I do not know how yet, other than using try catch, as assigned does not seem to work for Record fields.


110 How to use dsolve with Lie?

Use dsolve(ode,Lie)

To find symmetries, do

DEtools:-symgen(ode,y(x),HINT=[c__1+c__2*x+c__3*y,c__4+c__5*x+c__6*y])

or just

DEtools:-symgen(ode,y(x))

To debug it do

stopat(`ODEtools/symgen`); before calling dsolve or DEtools:-symgen

111 How to select terms with sqrt or radical in them from an expression

Given

\[ 3+x +\sqrt {-4 a c +b^{2}}+\sin \relax (y )+x^{3} \sqrt {39}+\sqrt {\cos }x \] Find terms that are sqrt. Use indets


\( \{ \sqrt {39}, \sqrt {-4 a c +b^{2}}, \sqrt {\cos }x \} \)

Alternative is to use type radical


\( \{ \sqrt {39}, \sqrt {-4 a c +b^{2}}, \sqrt {\cos }x \} \)

112 How to simplify \(e^{\ln (x)+\ln (y)}\)

given \[ {\mathrm e}^{\frac {2 \ln \left (\sqrt {p^{2}+1}+p \right )+2 \ln \relax (a )+\ln \left (p^{2}+1\right ) a}{2 a}}+{\mathrm e}^{3 x} \]

simplify(expr) does not work. So tried subsindets


\[ \left (\sqrt {p^{2}+1}+p \right )^{\frac {1}{a}} a^{\frac {1}{a}} \sqrt {p^{2}+1}+{\mathrm e}^{3 x} \]

It is possible to also try simplify(expr,exp) in some cases, but for the above example, this did not work, i.e. it did not simplify it.

113 How to find all csgn() and replace them by 1

I wanted to simplify an expression which could have csgn() in it, and find all the arguments.

\[ \frac {1+\mathrm {csgn} \relax (a ) a}{3 \mathrm {csgn} \relax (b ) b} \] One way is


\[ \frac {1+a}{3 b} \]

114 How to replace all abs(expr) by expr

I wanted to replace  |expr| by (expr)

One way is


115 How to find basis for Null space, Row space and column space of matrix?

Given \[ \left [\begin {array}{cccc}1 & -1 & 0 & 2 \\1 & 2 & 2 & -2 \\0 & 2 & 3 & -1 \end {array}\right ] \]

Find its Null, Row and Column space basis vectors.


\[ \left \{ \left [\begin {array}{c}0 \\2 \\-1 \\1 \end {array}\right ] \right \} \]


\[ \left [\left [\begin {array}{cccc}1 & 0 & 0 & 0 \end {array}\right ], \left [\begin {array}{cccc}0 & 1 & 0 & -2 \end {array}\right ], \left [\begin {array}{cccc}0 & 0 & 1 & 1 \end {array}\right ]\right ] \]


\[ \left [\left [\begin {array}{c}1 \\0 \\0 \end {array}\right ], \left [\begin {array}{c}0 \\1 \\0 \end {array}\right ], \left [\begin {array}{c}0 \\0 \\1 \end {array}\right ]\right ] \]

116 How to do Gaussian elimination on a Matrix?

Given \[ \left [\begin {array}{cccc}1 & -4 & -3 & -7 \\2 & -1 & 1 & 7 \\1 & 2 & 3 & 11 \end {array}\right ] \]

Find the new form after Gaussian elimination


\[ \left [\begin {array}{cccc}1 & -4 & -3 & -7 \\2 & -1 & 1 & 7 \\1 & 2 & 3 & 11 \end {array}\right ] \]

117 How to find Reduced Echelon form of a Matrix?

Given matrix \[ \left [\begin {array}{ccc}5 & 2 & 18 \\0 & 1 & 4 \\4 & 1 & 12 \end {array}\right ] \]

Find its Reduced Echelon form.


\[ \left [\begin {array}{ccc}1 & 0 & 2 \\0 & 1 & 4 \\0 & 0 & 0 \end {array}\right ] \]

Another option is


\[ \left [\begin {array}{ccc}1 & 0 & 2 \\0 & 1 & 4 \\0 & 0 & 0 \end {array}\right ] \]

118 How add a new row to bottom of matrix?

Given matrix \[ \left [\begin {array}{cc}1 & 1 \\2 & 3 \\4 & 5 \end {array}\right ] \] How to add row \[ [a, b] \] to end of the matrix?


\[ \left [\begin {array}{cc}1 & 1 \\2 & 3 \\4 & 5 \\a & b \end {array}\right ] \]

119 How to obtain list of all occurances of some function in an expression?

For an example, How to find list of all \(\ln \) functions in this expression?

\[ \ln \left ({| x +1|}\right )+2 x \ln \relax (x )+\sin \relax (x ) \]


To pick only \(\ln \) functions which has \(abs\) inside them anywhere, replace the above with


Or, better alternative to the above is


120 How to replace \(\ln (|x|)\) with \(\ln (x)\) in an expression?

Given

\[ \sin \relax (x )+\ln \left ({| x |}\right )+\ln \left (x +\frac {{| y |}}{\sqrt {{| x +3|}}}\right )+\ln \left (x^{3}\right )+\cos \left ({| x |}\right ) \]

How to remove the absolute, the ones only inside each \(\ln \) in the above expression?


\[ \sin \relax (x )+\ln \relax (x )+\ln \left (x +\frac {y}{\sqrt {x +3}}\right )+\ln \left (x^{3}\right )+\cos \left ({| x |}\right ) \]

121 How to find all signum functions in expression and simplify it?

Given

\[ -\frac {\left (\ln \left (\frac {\left (b +\sqrt {b^{2}+y \relax (x )^{2}}\, \mathrm {signum}\relax (b )\right ) b}{y \relax (x )}\right )+\ln \relax (2)\right ) \mathrm {signum}\relax (b )}{b} = \mathit {\_C1} +\frac {-\ln \relax (a )+\ln \relax (x )-\ln \left (a +\sqrt {a^{2}+x^{2}}\, \mathrm {signum}\relax (a )\right )-\ln \relax (2)}{{| a |}} \]

How to find all arguments of signum and simplify the above by assuming they are all positive?


\[ \frac {-\ln \relax (b )-\ln \left (\frac {b +\sqrt {b^{2}+y \relax (x )^{2}}}{y \relax (x )}\right )-\ln \relax (2)}{b} = \frac {\mathit {\_C1} a -\ln \relax (a )-\ln \left (a +\sqrt {a^{2}+x^{2}}\right )+\ln \relax (x )-\ln \relax (2)}{a} \]

122 How to do change of variables on the dependent variable for an ODE?

given an ode

\[ y \relax (x ) = \left (\frac {d}{d x}y \relax (x )\right )^{3} y \relax (x )^{2}+2 x \left (\frac {d}{d x}y \relax (x )\right ) \]

do change of variable \(u(x)=y(x)^2\)


\[ \sqrt {u \relax (x )} = \frac {\left (\frac {d}{d x}u \relax (x )\right )^{3}}{8 \sqrt {u \relax (x )}}+\frac {x \left (\frac {d}{d x}u \relax (x )\right )}{\sqrt {u \relax (x )}} \]

123 How to find the cofactor matrix of a matrix?

Use LinearAlgebra:-Adjoint and then transpose the result. Since the Adjoint is the transpose of the cofactor.

Given

\[ \left [\begin {array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 10 \end {array}\right ] \]

then


\[ \left [\begin {array}{ccc} 2 & 2 & -3 \\ 4 & -11 & 6 \\ -3 & 6 & -3 \end {array}\right ] \]

124 How to make phase plot of second order ODE?

Make a phase plot of \[ \frac {d^{2}}{d t^{2}}x \relax (t )+\frac {\frac {d}{d t}x \relax (t )}{2}+x \relax (t ) = u \relax (t ) \]

By plotting \(x(t)\) vs \(x'(t)\) without solving the ODE.


pict
Figure 1:Phase Plot

125 How to normalize eigenvectors?

When finding eigenvectors of matrix, using LinearAlgebra, the vectors are not normalized. How to normalized them so the length is one?

One way is


\[ v=\left [\begin {array}{ccc} -1 & 1 & 1 \\ 0 & \sqrt {2} & -\sqrt {2} \\ 1 & 1 & 1 \end {array}\right ] \]

\[ B=\left [\begin {array}{ccc} -\frac {\sqrt {2}}{2} & \frac {1}{2} & \frac {1}{2} \\ 0 & \frac {\sqrt {2}}{2} & -\frac {\sqrt {2}}{2} \\ \frac {\sqrt {2}}{2} & \frac {1}{2} & \frac {1}{2} \end {array}\right ] \]

126 How to find if some function is present in an expression

Given expression \(3 \sin \relax (x )+t +3 f \left (x , t\right ) t +g \left (x , t\right )\) find if it contains function \(f()\).

Use indets with specfunc(f)


   "Found f(x,t)"

127 How to find all functions in an expression?

Given expression \(3 \sin \relax (x )+t +3 f \left (x , t\right ) t +g \left (x , t\right )\) find all functions, if any, in the expression.

Use indets with function


   "Found these functions", {f(x, t), g(x, t), sin(x)}

128 How to find all functions in an expression but exclude all build in math functions?

Given expression \(3 \sin \relax (x )+t +3 f \left (x , t\right ) t +g \left (x , t\right )\) find all functions, if any, in the expression but exclude the math functions such as \(\sin \) in the above.


   "Found these functions", {f(x, t), g(x, t)}

129 How to obtain a list of all arguments of function?

use op


Note that op(0,f(x,t)) finds the function name.

130 How to obtain a list of all functions in expression whose first argument is \(z\)?


gives

"Found these functions", {f(z, t, y), sin(z)}

131 How to obtain a list of all functions in expression whose second argument is \(t\)?


gives

"Found these functions", {f(z, t, y), g(x, t)}

132 How to typeset \(\hslash \)?

expr:=`&hbar;`*x

gives

\[ \hslash x \]

Notice, the ; is needed. This `&hbar`*x will not work. It must be `&hbar;`*x

133 How to find the Curl of a vector?

First example


\begin {align*} F &= y \mathbf {\bar {e}_{x}}-x \mathbf {\bar {e}_{y}} \end {align*}

And now


\[ -2 \mathbf {\bar {e}_{z}} \]

Second example


\begin {align*} F &= y \,z^{2} \mathbf {\bar {e}_{x}}+(x \,z^{2}+2) \mathbf {\bar {e}_{y}}+(2 x y z -1) \mathbf {\bar {e}_{z}} \end {align*}

And now


\[ 0 \] Since Curl is zero, field is conservative.

Third example, in cylinderical coodinates


\begin {align*} F &= -\rho \mathbf {\bar {e}_{\phi }}+2 \mathbf {\bar {e}_{z}} \end {align*}

And now


\[ 2 \mathbf {\bar {e}_{z}} \]

134 How to see all steps in finding RREF form of an augmented matrix?

Use  Student:-LinearAlgebra:-GaussJordanEliminationTutor( A, output=steps )  Where \(A\) is your augmented matrix.

135 How to find column space of matrix?

Do not use the Maple command LinearAlgebra:-ColumnSpace for this. it gives the columns in the RREF. The correct way is to obtain the corresponding columns of the pivot columns in the original matrix \(A\). Hence use the command Basis like this


Which gives

\[ \left [\left [\begin {array}{c} 1 \\ 1 \end {array}\right ], \left [\begin {array}{c} 0 \\ 1 \end {array}\right ]\right ] \]

If you use ColumnSpace command you’ll get this


\[ \left [\left [\begin {array}{c} 1 \\ 0 \end {array}\right ], \left [\begin {array}{c} 0 \\ 1 \end {array}\right ]\right ] \]

These are different. Basis is the correct command to use, which matches the standard definition in textbooks.

136 How to use select with own type to find subexpressions?

Given expression such as \(3+(1+x)\sin x\) or \(3+(1+x)\sin ^2 x\) use select to find any  polynomial * sin^n  subexpressions.


Gives


137 How to write structured types to match some expressions?

137.1 type for \(\sin ^m(x)\cos ^n(x)\)


I could not find a way to avoid writing  Or('specfunc'(sin),'specfunc'(sin)^Or(integer,rational) in order to match both \(\sin x\) and \(\sin ^2 x\). For these things, I find Mathematica patterns more flexiable. The above can be done as follows in Mathematica


In Mathematica  n_.  says basically to match \(\sin x\) or \(\sin ^2 x\) since the dot says to match zero or more. So no need to duplicate things as I did above in Maple. There might be a way to do the same in Maple using structured type, but I could not find it. In General, I find patterns in Mathematica more flexible and easier to use for this sort of thing. Maple has patmatch command, but not as easy to use as Patterns in Mathematica.

138 How to use new object method calling in Maple 2021?

In Maple 2021, it is now possible to use object:-method(arg) notation. This makes is easier to use OOP in maple. To do this, use _self as follows


And now make an object and use it as follows


139 How to make a constructor for an Object?

Add ModuleCopy proc in the class. This will automatically be called to initialize the object.

Here is an example


And now make an object and use it as follows


So a constructor just makes it easier to initialize the object without having to make a number of set() calls to initialize each memeber data.

140 How to make different constructors for an Object?

This is done using overload with different ModuleCopy proc in the class.

Here is an example. Lets make a constructor that takes an ode and initial conditions, and one that only takes an ode with no initial conditions.


And now use it as follows


141 How to do OOP inheritance?

In the child class you want to extend from the parent class, add option object(ParentName);

Here is an example


In the above second_order_ode inherts all local variables and functions in the ODE class and adds new proc. Use as follows


Note that the child class can not have its own variable with the same name as the parent class. This is limitation. in C++ for example, local variables in extended class overrides the same named variable in the parent class.

Even if the variable have different type, Maple will not allow overriding. For example, this will fail


There might be a way to handle this, i.e. to somehow exlicitly tell Maple to override parant class proc or variable name in the child. I do not know now. The above is using Maple 2021.1

142 How to use object as user defined record inside a proc?

A Maple Object can be used a record type in other languags, such as Ada or Pascal. This example shows how to define a local type inside a proc and use it as record.


In the above person is local variable of type person_type. In the above example, the local variable was returned back to user. But this is just an example. One can declare such variables and just use them internally inside the proc only. This method helps one organize related variables into one record type. The type can also be made global if needed.

143 Given an expression with indexed variables, how to select only these variables?

use indets with type 'indexed'


144 How to show step by step for calculus problem?

For integration do


The steps are displayed. This does not work all the time. For example


gives

Error, (in Student:-Calculus1:-ShowSolution) unable to determine which calculus operation is 
being applied in this problem; you can provide this information as the 2nd argument on your 
call to Rule or Hint

145 How to obtain list of files with some extension in folder?

Use FileTools:-ListDirectory


In the above, files_to_process is a list of the files in the current folder with extension .tex

146 How to delete lines from text file that contains some string?

There was a case when I needed to delete lines from text file that contains a say "foo" as an example.

This is what I did. use readline to read the lines, check, and if the line contains "foo" skip, else write the line to a temporary file. At the line, use Rename to rename the temporary file to the file being read.


147 Given an expression, how to find all variables and functions in it?

Given say \(\frac {d^{2}}{d x^{2}}y \relax (x )+n \left (\frac {d}{d x}y \relax (x )\right )+3 = \sin \relax (x )\) how to find all variables and functions in it, not including math functions such as \(\sin x\)?

So the result should be \(n,x,y(x)\).


I still need to work on excluding derivatives from the search.

148 How to check if an expression is integer, when it has symbols in it?

I had case where I needed to check if something is integer or not. The problem is that the result had a symbol \(n\) in it. I need a way to tell Maple that to check if the result can be an integer given that \(n\) is also an integer.

Using type does not work, since can’t use assumptions. One way is to use coulditbe as follows


In the above indets(expr,And(symbol,Not(constant))) picks all variables in the expression, and assuming op(map(Z->Z::integer,vars)) makes assumption that each is integer.

149 How to invert roles of dependent variable and independent variable in an ode?

Sometimes it is useful to invert an ode. i.e. make the independent variable the dependent variable, and the dependent variable the independent. For example, given \[ 1+\left (\frac {x}{y \relax (x )}-\sin \left (y \relax (x )\right )\right ) \left (\frac {d}{d x}y \relax (x )\right ) = 0 \] We want the ode to become \[ -\sin \relax (y ) y +y \left (\frac {d}{d y}x \relax (y )\right )+x \relax (y ) = 0 \]

This can be done as follows


\[ \frac {-\sin \relax (y ) y +y \left (\frac {d}{d y}x \relax (y )\right )+x \relax (y )}{y \left (\frac {d}{d y}x \relax (y )\right )} = 0 \]

In this case, we can get rid of the denomator, but this is a manual step for now.


\[ -\sin \relax (y ) y +y \left (\frac {d}{d y}x \relax (y )\right )+x \! \relax (y ) = 0 \]

The above can now be solved more easily for \(x(y)\) than solving the orignal ode for \(y(x)\).

150 How to truncate a polynomial?

Given \(9 x^{5}+4 x^{4}+3 x^{3}+x^{2}+x +1\) how to truncate it, so that all terms of \(x^3\) and higher are removed?

This can be done as follows


\[ x^{2}+x +1 \]