0% found this document useful (0 votes)
35 views2 pages

CHS359 - Solution To Quiz 3

This document provides solutions to a quiz involving a third order linear ordinary differential equation (ODE). It gives: 1) The analytical solution to the ODE using its characteristic roots and initial conditions. 2) Writes the ODE in state-space form with a 3D state vector. 3) Defines a MATLAB function for the ODE. 4) Provides a MATLAB script that numerically solves the ODE and compares the solution to the analytical one.

Uploaded by

Haitham Osman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

CHS359 - Solution To Quiz 3

This document provides solutions to a quiz involving a third order linear ordinary differential equation (ODE). It gives: 1) The analytical solution to the ODE using its characteristic roots and initial conditions. 2) Writes the ODE in state-space form with a 3D state vector. 3) Defines a MATLAB function for the ODE. 4) Provides a MATLAB script that numerically solves the ODE and compares the solution to the analytical one.

Uploaded by

Haitham Osman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CHS359 - Solution to Quiz 3

Consider a linear ODE given by


...
y (t) + 4y(t) + 30y(t) + 52y(t) = 0 (1)
with initial conditions y(0) = 2, y(0) = 13, y(0) = 0.
1. (10 points.) Find the analytical solution to (1) according to the given initial conditions
for t 0, by hand. The solution y(t) has the form
y(t) = C1 e1 t + C2 e2 t + C3 e3 t , t 0.
You may use MATLAB to solve for k , Ck for k = 1, 2, 3.

Solution. The auxillary equation of the ODE is


(3 + 42 + 30 + 52) = 0
We can find the roots of this equation using roots command by

>> s = roots([1 4 30 52])

s =

-1.0000 + 5.0000i
-1.0000 - 5.0000i
-2.0000

The three roots are 1 = 1 + 5j, 2 = 1 5i and 3 = 2. The solution has the
form
y(t) = C1 e1 t + C2 e2 t + C3 e3 t
where C1 , C2 , C3 can be found from the initial conditions. To this end, we need to find
the first and second derivatives of y(t).
y(t) = 1 C1 e1 t + 2 C2 e2 t + 3 C3 e3 t
y(t) = 21 C1 e1 t + 22 C2 e2 t + 23 C3 e3 t
Evaluate y(t), y(t), y(t) at t = 0 and then we have

y(0) C1 + C2 + C3 1 1 1 C1
y(0) = 1 C1 + 2 C2 + 3 C3 = 1 2 3 C2 .
y(0) 21 C1 + 22 C2 + 23 C3 21 22 23 C3
This is a linear equation Ax = b where x is the vector of C1 , C2 , C3 , so they can be
solved by

s = [-1+5*i -1-5*i -2];


A = [1 1 1;s ; s.^2]
b = [2 -13 0];
C = A\b

C =

0.5000 + 1.0000i
0.5000 - 1.0000i
1.0000 - 0.0000i

1
Therefore, C1 = 0.5 + j, C2 = 0.5 j, C3 = 1. The solution to ODE is

y(t) = (0.5 + j)et (cos 5t + j sin 5t) + (0.5 j)et (cos 5t j sin 5t) + e2t
= e2t + et (cos 5t 2 sin 5t)

2. (2 points.) Write the ODE (1) in a state-space form, x = f (x). What is the dimension
of x ?
Solution. The equation is a 3rd-order ODE, so we need 3 components in a state
[ ]T
variables. Define x = x1 x2 x3 and x1 = y, x2 = y, x3 = y. The state-space
equation is obtained by

x1 x2
x2 = x3 .
x3 4x3 30x2 52x1

3. (3 points.) Write the ODE description (the function f (x)) as a user-defined function
which returns a value of x at given values of t and x. The function format must be
[dx] = odequiz3(t,x). Save this file in D:\CHS359\idxxx.
Solution.

function dx = odequiz3(t,x)
dx = zeros(3,1);
dx(1) = x(2);
dx(2) = x(3);
dx(3) = -4*x(3)-30*x(2)-52*x(1);

4. (5 points.) Write a MATLAB script to compute a numerical solution of (1) using an


ODE solver such as ode45, from t = 0 to t = 10. Compare the graphs of the numerical
and analytical solutions in a single plot. Your codes must be written in run.m and the
file MUST be saved in D:\CHS359\idxxx
Solution. An example of codes in run.m is

[t,x] = ode45(@odequiz3,[0 10],[2 -13 0]);


y = exp(-2*t)+exp(-t).*(cos(5*t)-2*sin(5*t));
plot(t,x(:,1),t,y);

1.5

0.5 The graphs obtained from the numerical


and analytical solutions should aligned
0
perfectly as shown in the figure
0.5

1.5
0 2 4 6 8 10

You might also like