Starting from:
$30

$24

Homework 6 Solution




Please submit to CANVAS a .zip le that includes the following Matlab functions:




tridiag solver.m







AB3.m




solve ODE system.m










Exercise 1 Write a Matlab function that implements the Thomas algorithm to solve tridiagonal linear systems of equations in the form




2 a1
c1
0
.. .


6
e1
.a.2
.c.2
..
.


6
0


..




6














6
.. ..
.


an


1
6
.






6














6














6
0




0
en


1
4


















0
3
2
x1
3


2
b1
3


0
7
x2


b2


0
6
..
7
=
6
..
7
(1)
7
.


.




7
6


7


6


7


cn 1
7 6
xn 1
7


6
bn 1
7


7
6


7


6


7




7
6


7


6


7


an
7
6
xn
7


6
bn
7


7
6


7


6


7




5
4


5


4


5


The function should be in the form




function x = tridiag solver(e,a,c,b)







Input:




e=[e1 e2 en 1] a=[a1 a2 an] c=[c1 c2 cn 1] b=[b1 b2 bn]T




Output:




x: solution to the linear system (1) (column vector)










Exercise 2 Consider the system of nonlinear ordinary di erential equations


8
dt = f(y(t); t)
(2)
dy(t)

<







: y(0) = y0




where f : Rn [0; T ] ! Rn, y : [0; T ] ! Rn. Write a Matlab function that solves the system (2) by using the third-order Adams-Bashforth scheme. To start-up the scheme ( rst two steps) use the











Heun scheme. The function should be of the form




function [y,t] = AB3(fun,y0,T,DT,IOSTEP)




Input:




fun: function handle representing f(y; t)




y0: column vector representing the initial condition




T: period of integration




DT: time step




IOSTEP: Input/output step. The solution is saved in the output matrix y every IOSTEP steps.




Output:




y: n S matrix collecting the time snapshots of the solution to (2). Note that the total number of snapshots S (including the initial condition) is floor(T/(IOSTEP*DT))+1.




t: vector collecting the time instants at which the solution is saved in the output matrix y.







Exercise 3 Consider the following nonlinear dynamical system


















8
dy1(t)
= y1(t) + y2(t)y3(t)


dt



dy2(t)
= y2(t) + (y3(t) 2)y1(t)
(3)








dt
















<





















dy3(t)
= 1 y1(t)y2(t)


dt




:







It is known that the solution to (3) is chaotic in time and it settles on a strange attractor. By using the function AB3.m you coded in Exercise 2, compute the numerical solution to (3). To this end, set NSTEPS=1000000, IOSTEP=50, DT= 1e-3, y0=[1 2 3]T , and write a function




function [y,t]=solve ODE system()







Output:




y: 3 S matrix collecting S time snapshots of the solution to (3). Here, S=floor(NSTEPS/IOSTEP)+1.




t: vector collecting the time instants at which the solution is saved in the output matrix y.




The function solve ODE system should also return the following items:







The plots of the trajectories y1(t), y2(t) and y3(t) versus time in figure(1).



A three-dimensional plot of the curve (y1(t); y2(t); y3(t)) in figure(2) (use the command plot3()).






2

More products