MatLab graphing facilities:
plot, subplot, title.
Now we are going to use these functions to plot the input and output
of a RLC-circuit or a mass-spring system.
Here is an example.
Recall that in class we solved the following problem:
I''+4I'+20I=E'(t), where E(t)=85sin(4t), I(0)=0 and I'(0)=0.
The solution of this initial value problem is:
I(t)=e-2t(-cos(4t)-4.5sin(4t))+cos(4t)+4sin(4t).
Observe that as t is getting larger and larger, the term
e-2t is getting closer and closer to zero, and the solution
becomes
Iss(t)=cos(4t)+4sin(4t)
which is called the steady-state solution of I(t).
The following commands are used to plot the graphs of
the input E(t) and outputs I(t) and Iss(t) for 3 periods.
(Recall the period of functions sin(bt) and cos(bt) is 2pi/b. So
the period for sin(4t) is pi/2.)
clf %clear the screen
t=0:.01:3*pi/2;
cur=exp(-2*t).*(-cos(4*t)-4.5*sin(4*t))+cos(4*t)+4*sin(4*t);
sscur=cos(4*t)+4*sin(4*t);
volt=85*sin(4*t);
subplot(211),plot(t,volt)
title('RLC - circuit, voltage E(t)=85sin(4t)')
subplot(212),plot(t,cur,'--',t,sscur,':')
title('-- current I(t), ... current in the steady-state')
The graphs are given at the end of this assignment.
Here are your first two assignments.
- Consider the initial value problem in the Problem 2 of Homework #18:
I"+2I'+2I=5cost, I(0)=0, I'(0)=0.
Know that the solution is:
I(t)=-e-tcos(t)-3e-tsin(t)+cos(t)+2sin(t).
Plot the voltage E(t)=500sin(t), the current I(t) and its steady-state
current Iss for 3 periods. Have the graph of
E(t) in one window, and graphs of I(t) and Iss in one window.
- Consider the initial value problem in the Problem 1(b)
of Homework #18:
y"+4y=sin(t) + 1/3 sin(3t) + 1/5 sin(5t), y(0)=1, y'(0)=3/35.
Know that the solution is:
y(t)=cos(2t)+1/3sin(t)-1/15sin(3t)-1/105sin(5t).
Plot the external force function
F(t)=sin(t) + 1/3 sin(3t) + 1/5 sin(5t) and the displacement
y(t) for t from 0 to 6pi in two separate windows.
MatLab has functions
ode23 and ode45 which solve numerically initial value problems
for first order differential equations y'=f(t,y), y(a)=y0 or
systems of first order differential
equations Y'=F(t,Y), Y(a)=Y0.
Type help ode23 and help ode45
to learn more about these two functions. Here is an
example which uses ode23 and ode23 to solve the initial
value problem:
y'=-y/sqrt(2-y2), y(0)=1, 0 <= t <= 5.
First we create a MatLab function (a text file) called fun1.m
which evaluates the function f(t,y)=-y/sqrt(2-y2) for
give (t,y). The file fun1.m is as follows.
function f=fun1(t,y)
f=-y/sqrt(2-y^2);
Now we use MatLab functions ode23 and ode45
to solve the initial value problem numerically and then plot the
numerical solutions y, respectively. In the MatLab window,
>> clf
>> clear
>> [tv1 f1]=ode23('fun1',[0 5],1);
>> [tv2 f2]=ode45('fun1',[0 5],1);
>> plot(tv1,f1,'-.',tv2,f2,'--')
>> title('dy/dt=-y/sqrt(2-y^2), y(0)=1')
The graph is given below. Try it yourself to see if you will
get the same graph.
Here is your last part of the assignment. Solve the
following initial value problem using MatLab functions
ode23 and ode45 and plot the numerical solutions.
y'=ty+2t-y^3, y(0)=0, 0 <= t <= 4.5.
Are solutions obtained by these functions close?
Graphs of the examples: