Prof. Vladimir A. Dobrushkin
This tutorial contains many Matlab scripts.
You, as the user, are free to use all codes for your needs, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to
I. Verification
function solveDifferentialEquation
%This function solves y'+y = x from starttime to endtime with y(0) = intialCondition
%Parameter initializations
starttime = 0;
endtime = 20;
initialCondition = -2;
function yprime = DifferentialEquationFunction(x,y)
yprime = y - x;
end
[xVals,yVals] = ode45(@DifferentialEquationFunction,[starttime,endtime],initialCondition);
plot(xVals,yVals);
end %Function Complete
%Function Complete
Example 1.1.1:
Example 1.1.2:
II. Plotting
Consider a plane problem governed by the system of autonomous equations
function project
close all;
for n = -4:4
[t,sol]=ode45(@diffeq,[0,10],[n;n]);
plot(sol(:,1),sol(:,2))
hold on
[t,solu]=ode45(@diffeq,[0,-10],[n;n]);
plot(solu(:,1),solu(:,2))
end
X_label1 = xlabel('X');
Y_label1 = ylabel('Y');
set(X_label1,'FontSize',12);
set(Y_label1,'FontSize',12);
function dwdt = diffeq(t,w)
%x' = x^2 -3xy
%y' = 2xy -y^2
%Since x = x(t) and y(t)
%x' = x^2-3x^2=-2x^2
%y' = 2x^2-x^2= x^2
x1 = w(1);
y1 = w(2);
dx1dt = (x1)^2 -3*x1*y1;
dy1dt = 2*x1*y1 -(y1)^2 ;
dwdt = [dx1dt;dy1dt];
end
end

Enter text here