Mathematica note

The following are examples of some important commands in Mathematica.

Equations

Differentiation/Integration

Matrices/vectors

   mat1={{a11, a12, a13}, {a21, a22, a23}, {a31, a32, a33}}
   vec={v1, v2, v3}
   mat1.vec
   Inverse[mat1]
   Eigenvalues[mat1]
 

Differential equations

   DSolve[ y'[x]- a y[x]==1, y[x], x]
   DSolve[ {y'[x]- a y[x]==1, y[0]==0},y[x],x]
   DSolve[ { x'[t]==y[t], y'[t]==x[t]}, {x[t], y[t]}, t]
 

Functions

   f[x_]:= x*Sin[x];
   f[x_, y_]:= (x-y)^4;
   delta[i_, j_]:= If [i==j, 1, 0];
 

Misc.

   Plot[ Sin[x], {x, -Pi, Pi}]
   Plot[ { Sin[x], Cos[x]}, {x, -2Pi, 2Pi}]
   Plot3D[ Exp[-x*y], {x, -4, 4}, {y, -1, 10}]
   N[Pi, 1000]
   I^200
   Exp[E]
   x^3/.x-> 1+y
   (x^2+y^3)/.{x->2, y-> 16}
   Series[Sin[x], {x, 0, 100}]
   Apart[1/(x^2-4)]
   Sum[ 1/i!, {i, 1, 100}]
   Sum[ 1/i!, {i, 1, 100}]//N
   NSum[1/i!, {i, 1, 100}]
 

Random Commands/Functions in Mathematica

2^100//N Converts symbolic values to numeric values.
1/3+2/7Symbolic values
1/3+3/7//NNumeric values
Sqrt[x]Note the use of [].
Exp[x]Exponential function
Log[x]Natural logarithm
Log[b, x]Logarithm with base b
Sin[x], Cos[x], Tan[x]Trignometric functions
ArcSin[x], ArcCos[x], ArcTan[x]Hyperbolic trignometric functions
n!Factorial
Abs[x]Absolute value
Random[]Randome number
Max[x,y,...], Min[x, y, ...]Maximum, minimum
Pip=3.141592....
Ee=2.71828....
Degree1/100 radian
Iimaginary number
Infinityoo
expression//N or N[expression]Numeric values
N[expression, n]Numerica value with n-digit precision
x + I ycomplex number, x + i y
Re[z]Real part
Im[z]Imaginary part
Abs[z]Absolute value |z|
Conjugate[z]Complex conjugate
Arg[z]Argument of angle
%last result generated
%%next-to-last resutl
%nresult on output line Out[n]
x=valueassign a value to x
x=y=valueassign a value to both x and y
Clear[x]remove any value assigned to x
x y means x times y
xy with no space is the variable with name xy
5x meanx 5 times x
{a, b, c} a list

 v={1, 2, 3,4}

 v[[1]]=4
expression/. x -> value replace x by value in the expression
expr/.{x-> xval, y-> yval}
 t=1+x^2
 t/.x->2
 t/.x->5a
Expand[ (1+x)^2]
Factor[%]

Simplify[ x^2+2x+1]

Integrate[1/(x^4-1),x]

D[%,x]

Simplify[%]


a=(x-1)^2 (2+x)/ ( (1+x) (x-3)^2)

Expand[a]

Together[%]

Apart[%]

Factor[%]
e=Expand[(1+3x+4y^2)^2]

Coefficient[e,x]

Exponent[e,y]


r= (1+x)/( 2 (2-y))

Denominator[r]

Numerator[r]

D[x^n, x]

D[ArcTan[x], x]

D[x^n, {x, 3}]


Integrate[x^n, x]

Integrate[1/(x^4-a^4), x]

Integrate[Sin[x^2], x]

Integrate[ x^2, {x, 0, 1}]

N[%]

Integrate[ x^2+y^2, {x, 0, 1}, {y, 0, 1}]

Sum[i^2, {i, 1, n}]

Sum[1/i^2, {i, 1, Infinity}]

Solve[x^2+2x-7==0, x]

Solve[ x^4-5 x^2-3==0, x]

DSolve[ y''[x]+y[x]==0, y[x], x]

Series[ Exp[x], {x, 0, 5}]

Limit[ Sin[x]/x, x->0]

N[(3+Sqrt[2])]

NSum[1/i^3, {i, 1, Infinity}]

NIntegrate[ 1/Sqrt[ x (1-x)], {x, 0, 1}]

NIntegrate[ Exp[-x^2], {x, -Infinity, Infinity}]


NSolve[ x^5+x+1==0, x]

NSolve[ {x+y==2, x-3y==3, x-y+z==0}, {x, y,z}]

FindRoot[ 3 Cos[x] == Log[x], {x, 1}]

data=Table[Exp[x/5.0], {x, 7}]

Fit[ data, {1, x, x^2}, x]

f[x_]:=x^2
Clear[f]

Do[ Print[ i], {i, 5}]
Do[ Print[i], {i, 2, 10, 2}]
Print[expression]
Table[ expression, {i, imax}]
Table[i!, {i, 4}]
{a,b,c} ... vector(a,b,c)
{{a,b},{c,d}} ... matrix

m={{ 1, 4}, {2, 5}}
m[[1,2]]

v={4,5}

m.v .... Product between matrix and vector

MatrixForm[m]

Inverse[m]
Det[m]
Eigenvalues[m]
Eigenvectors[m]

Plot[ Sin[x], {x, 0, 2Pi}]
Plot[Tan[x], {x, -3, 3}]
Plot[{Sin[3x], Sin[2x]}, {x, 0, 2Pi}]

Plot[ Sin[1/x], {x, -1, 1}]

ContourPlot[ Sin[x] Sin[y], {x, -2,2},{y,-2,2}]
DensitPlot[ Sin[x] Sin[y], {x, -2,2},{y,-2,2}]
Plot3D[ Sin[ x y], {x, 0,3},{y, 0, 3}]

t=Table[ i^2, {i, 10}]
ListPlot[t]
ListPlot[t, PlotJoined->True]

ParametricPlot[ {Sin[t], Sin[2t]}, {t, 0, 2Pi}]
ParametricPlot3D[ { Sin[t], Cos[t], u}, {t, 0, 2Pi}, {u, 0, 4}]
ParametricPlot3D[ { Cos[t] (3+Cos[u]), Sin[t](3+Cos[u]), Sin[u]}, {t, 0, 2Pi}, {u, 0, 2Pi}]

sol=NDSolve[ {x'[t]==-3 (x[t]-y[t]),
y'[t]==-x[t] z[t]+26.5 x[t]-y[t],
z'[t]==x[t] y[t]-z[t],
x[0]==z[0]==0, y[0]==1},
{x,y,z}, {t, 0, 20}, MaxSteps->3000];

ParametricPlot[ Evaluate[{x[t], z[t]} /.sol], {t, 0, 20}, PlotPoints -> 1000]

ParametricPlot3D[ Evaluate[ {x[t],y[t],z[t]}/.sol], {t,0,20},PlotPoints->1000]



Expand[ (x+y)^3] >> tmp.m
<<tmp.m

Directory[]
SetDirectory["/tmp"]





File translated from TEX by TTH, version 4.03.
On 22 Jan 2023, 08:49.