0% found this document useful (0 votes)
11 views5 pages

HW 02

The document outlines a homework assignment for ELEC 360, focusing on solving Ordinary Differential Equations (ODEs) using Matlab's ode45() function. It provides examples of first and second order ODEs, including how to represent them as functions in Matlab and plot their solutions. Additionally, it introduces problems that involve handling inputs in the system and requires students to provide commented code for their solutions.

Uploaded by

m9x
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)
11 views5 pages

HW 02

The document outlines a homework assignment for ELEC 360, focusing on solving Ordinary Differential Equations (ODEs) using Matlab's ode45() function. It provides examples of first and second order ODEs, including how to represent them as functions in Matlab and plot their solutions. Additionally, it introduces problems that involve handling inputs in the system and requires students to provide commented code for their solutions.

Uploaded by

m9x
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/ 5

ELEC 360 – Signals and Systems

Spring 2024
HW #2
In Matlab, you can solve Ordinary Differential Equations (ODEs) numerically. The most commonly
used Matlab function used for such applications is ode45(). Read the documentation to
understand how it works.
( )
Example: Let’s have an ODE as such, + 4𝑦(𝑡) = 0, 𝑦(0) = 5. We want to find 𝑦(𝑡) in the range
0 ≤ 𝑡 ≤ 10
( )
For ode45(), you need to represent the ODE as a function in the form = 𝑓 𝑡, 𝑦(𝑡) for the
current 𝑡

As such, we start by creating a Matlab function func_f.m:

File: func_f.m
function dy = func_f(t, y)
% t is a scalar, and is the current time
% y could be a vector, is the current value y at time t
% dy is the current value of the derivative of y at time t
dy = -4*y;
end
This function above describes the ODE. (Note that obviously you can call this function whatever you
want as long as its name doesn’t overlap with another function you plan to use)

Next, we can solve for 𝑦(𝑡) from the function ode45() by running the script in the Command
Window:

>> tspan = 0:0.001:10;


>> y0 = 5;
>> [t, y] = ode45(@func_f, tspan, y0);
>> plot(t, y);
You should be getting the plot seen below.
ELEC 360 – Signals and Systems
Spring 2024
HW #2
Note that if your system had multiple “states”, y0 above, and even y and dy in the func_f()
function can be vectors. For instance, given:

𝑑𝑦 (𝑡)
+ 4𝑦 (𝑡) + 5𝑦 (𝑡) = 0,
𝑑𝑡
𝑑𝑦 (𝑡)
+ 𝑦 (𝑡) + 2𝑦 (𝑡) = 0.
𝑑𝑡
In addition: 𝑦 (0) = 1, 𝑦 (0) = 2

( ) 𝑦 (𝑡)
Our new function func_2f() representing = 𝑓 𝑡, 𝑦(𝑡) where 𝑦(𝑡) = is
𝑦 (𝑡)

File: func_2f.m
function dy = func_2f(t, y)
% t is a scalar, and is the current time
% y is a vector, is the current value y at time t
% dy is the current value of the derivative of y at time t
dy1 = -4*y(1) - 5*y(2);
dy2 = -1*y(1) - 2*y(2);
dy = [dy1; dy2]; % Column vector
end
Next, our script will be:

>> tspan = 0:0.001:10;


>> y0 = [1; 2];
>> [t, y] = ode45(@func_2f, tspan, y0);
>> plot(t, y(:, 1)); % Means we're taking the first column
>> hold on % So that next plot adds onto the figure
>> plot(t, y(:, 2), 'r'); % plotting y2
And the figure will look as follows (for both 𝑦 (𝑡) and 𝑦 (𝑡))
ELEC 360 – Signals and Systems
Spring 2024
HW #2
Problem 1 (50 points)
Now what do we do if the ODE was second order? Well in previous courses, you’ve learned that you
can represent 2nd order systems as 2 first order differential equations.

Given:

𝑑 𝑦(𝑡) 𝑑𝑦(𝑡)
+3 + 9𝑦(𝑡) = 0,
𝑑𝑡 𝑑𝑡
And 𝑦(0) = 0, 𝑦̇ (0) = 2

First show your transformed ODEs (the new two first order ODEs)

Then, plot 𝑦(𝑡) for the time range 0 ≤ 𝑡 ≤ 10.

Provide all your codes commented.

Problem 2 (50 points)


What do we do when we have an input into the system explicitly given? In addition, our system does
( )
not need to be linear nor invariant to solve using ode45(). You just need to provide in terms of
𝑡 and 𝑦(𝑡) as a Matlab function.

Given:
𝑑𝑦(𝑡)
(2 + sin 𝑦(𝑡)) + 5𝑡 𝑦(𝑡) = 𝑥(𝑡),
𝑑𝑡
𝑦(0) = 0, and 𝑥(𝑡) = (1 − 𝑒 )𝑢(𝑡 − 1)

(Note that the step function in the input is shifted to the right).

(You can mimic step function by just having if statements in your ODE function).

Plot 𝑦(𝑡) for the time range 0 ≤ 𝑡 ≤ 10.

Provide all your codes commented.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy