ODE Text Mathematica Examples

Example 1.1.10

A={{1,2,3},{4,5,6},{7,8,2}};
b={-1,4,-7};
newa=Transpose[Insert[Transpose[A],b,4]];
MatrixForm[RowReduce[newa]]

Matrix Algebra

A = {{1,2,3},{4,-5,6}};
B = {{-2,5,-8},{-7,9,3}};
Cee = {{-3,5},{2,1},{9,-7}};
a = {4,-7,9};
b = {2,-6,5};
AB = 2*A-5*B;
ab = 4*a+7*b;
AC = A.Cee;
CA = Cee.A;
ACinv = Inverse[AC];
MatrixForm[AB]
MatrixForm[ab]
MatrixForm[AC]
MatrixForm[CA]
MatrixForm[ACinv]
MatrixForm[AC.ACinv]

Example 1.4.5

A = {{1,2,3},{-1,2,-3},{5,6,7}};
Ainv = Inverse[A];
MatrixForm[Ainv]

Example 1.5.6

RowReduce[{{3,4,7,-1},{2,6,8,-4},{-5,3,-2,-8},{7,-2,5,9}}]

MatrixForm[%]

RowReduce[{{1,2,3,-3},{2,1,3,0},{1,-1,0,3},{-3,2,-1,-7}}];
MatrixForm[%]

Example 1.7.9

RowReduce[{{1,2,3,4},{-1,2,1,0},{5,6,11,16},{2,4,6,8}}];
MatrixForm[%]

A ={{-3,4,8,-2},{2,6,8,-4},{-5,-9,-2,-8},{7,-2,5,9}};
MatrixForm[%]
Det[A]

Compute the determininant

Example 1.12.7

A ={{1,2,3},{-1,2,-3},{5,6,7}};
MatrixForm[A]
N[Eigenvectors[A],5]

Case Study 1.13.2
Eigenvalues and associated eigenvectors for M

M ={{9/10,3/100,1/10},{2/100,85/100,2/10},{8/100,12/100,7/10}};
Eigenvectors[M]

Rescaled eigenvector v1

v1={35/24,55/36,1};
MatrixForm[v1/(35/24+55/36+1)]

Case Study 1.13.3
Eigenvalues and associated vectors for A

A = {{2/10,0,1/100},{8/10,5/10,0},{0,5/10,99/100}};
Eigenvectors[A]
Eigenvalues[A]

Rescale eigenvector v1

v1={1/80,1/50,1};
MatrixForm[v1/(1/80+1/50+1)]

Case Study 1.13.4
Eigenvalues and associated eigenvectors for A

A={{0,0,33/100},{18/100,0,0},{0,71/100,94/100}};
N[Eigenvectors[A],5]
N[Eigenvalues[A],5]

Rescaled eigenvector v1

v1={0.3355,0.0614,1};
MatrixForm[v1/(0.3355+0.0614+1)]

Solve Pc=x0 by finding inverse of P

v1={0.240177541311969,0.0439531075092037,0.715869351178827};
v2={1,-0.009150128540143671\[Hyphen]0.8644469584876894*I,-0.06604960570424193+0.6239953953635560*I};
v3={1,-0.09150128540143671+0.8644469584876894*I,-0.06604960570424193\[Hyphen]0.6239953953635560*I};
Ptr={v1,v2,v3};
P=Transpose[Ptr];
Pinv=Inverse[P];
N[MatrixForm[P],5]

Example 2.4.4

a=-Exp[-3*t]*Sin[2*t];
A=Integrate[a,t]

Example 2.5.4

f=t^2/(4+t);
F=Integrate[f,t];
xp=(4+t)*F

Example 2.5.11

f=t*Sin[2*t]*Exp[-5*t];
F=Integrate[f,t];
xp=Exp[5*t]*F

Case Study 2.6.1

Clear[a,c,t,w,v]
f=Exp[a*t]*(1-Cos[w*t]);
F=Integrate[f,t];
xp=a*c*v*Exp[-a*t]*F

Exercise 2.6.9 - finding zeros of a function

f=Sin[x]-0.6*x+0.05;
Plot[f,{x,-10,10}]

FindRoot[f,{x,-2}]
FindRoot[f,{x,-1}]
FindRoot[f,{x,1}]

Case Study 3.7.1

Clear[a,c,w,V]
Cee={{-2*a,a,-w,0},{a,-2*a,0,-w},{w,0,-2*a,a},{0,w,a,-2*a}};
cf={a*V*c,0,0,0};
cans=LinearSolve[Cee,cf]

Simplify each component of the solution vector

Factor[cans[[1]]]
Factor[cans[[2]]]
Factor[cans[[3]]]
Factor[Det[Cee]]

Case Study 3.7.2

A={{-13/360,272/21875,7/200000},{1/90,-1/35,0},{7/1800,0,-7/200000}};
N[Eigenvectors[A],5]
N[Eigenvalues[A],5]

f={49+3/10,0,0};
a0=LinearSolve[-A,f]

Case Study 3.7.3

A={{-1/2,1/80,73/80},{1/4,-961/80,0},{1/4,12,-73/80}};
N[Eigenvectors[A],5]
N[Eigenvalues[A],5]

{1,20/961,38420/70153}/(1+20/961+38420/70153)

A = {{-1,1/80,1/16},{1/2,-961/80,0},{1/2,12,-1/16}};
N[Eigenvectors[A],5]
N[Eigenvalues[A],5]

{1,40/961,15368/961}/(1+40/961+15368/961)

Plot multiple functions on one graph

f=Exp[-x]*(x^2*Cos[2*x]-1);
g=x^3/(1+x^6);
Plot[f,g]

Plot[{f,g},{x,0,12},PlotRange->All,PlotStyle->{Red,Dashed,Thick}]

Example 4.1.3 - roots of a polynomial will be found by finding the eigenvalues of the companion matrix for the ODE

A={{0,1,0,0},{0,0,1,0},{0,0,0,1},{-9,-6,3,0}};
MatrixForm[A]
N[Eigenvalues[A],5]

Example 5.2.10

f1=Exp[-s*t]*t;
f2=Exp[-s*t]*(t^2-2);
F1=Integrate[f1,{t,0,2}];
F2=Integrate[f2,{t,2,Infinity}];
F=Factor[F1+F2]

Example 5.2.13

F=(s^4+6*s^3-15*s^2-10*s+50)/(s^3*(s^2-2*s+10));
Apart[F]