Sie sind auf Seite 1von 3

Name___________________________________ Matrix______________________ H/P_______________________ Subject:

KE26503

Assignment 2

MATLAB m-file (with graph for solution)


Second order linear and non-homogeneous differential equation:
d2y/dt2 + 3dy/dt + 2y = cos2t

MATLAB-SIMULINK (with graph for solution)

KE26503 Differential Equations

1415(1) Assignment #2

Name___________________________________ Matrix____________________ H/P:___________________


Subject: KE00103 / KS20303 / KA / KM

(a) Discussion of all the methods and solution

MATLAB m-file
For example, in order to solve the second order equation:
d2y/dt2 + 3dy/dt + 2y = cos2t with y(0) = 0 and dy/dt t=0 = 1
for 0 t 10 we must define a variable x such that:
x = dy/dt
Thus we can rewrite the differential equation as:
d2y/dt2 = 3dy/dt 2y + cos2t
or in terms of x: dx/dt = 3x 2y + cos2t

KE00103 / KS20303

Test #2

Differential Equations

0910(2)

Name___________________________________ Matrix____________________ H/P:___________________


Subject: KE00103 / KS20303 / KA / KM

We will use the ode45 command to solve the system of first order
differential equations:
dx/dt = 3x 2y + cos2t
dy/dt = x
We place these two equations into a column vector, z, where:
z=

x
y

dz /dt = dx / dt
dy /dt

A function is created in a MATLAB m-file to define dz/dt named f2 which


contains:
function dz=f2(t,z)
dz=[-3*z(1)-2*z(2)+cos(2*t); z(1)];
>> initz=[1; 0];
and the equations are solved and plotted using:
>> [t,z]=ode45(@f2, t, initz);
>> plot(t, z(:,2))

MATLAB-SIMULINK
The second order differential equation, d 2y/dt 2 + 3dy/dt + 2y = cos2t in
Simulink. This equation can be re-written as, d 2y/dt 2 = 3dy/dt 2y +
cos2t. In order to get the three input subtractor, use the two input
subtractor.In order to get y and dy/dt we need to integrate the output of
this summer twice. Simulate the circuit for 10 seconds

KE00103 / KS20303

Test #2

Differential Equations

0910(2)

Das könnte Ihnen auch gefallen