%% HOW DO I DO THAT IN MATLAB SERIES?
% In this series, I am answering questions that students have asked
% me about MATLAB. Most of the questions relate to a mathematical
% procedure.
%% TOPIC
% How do I solve a 2nd order diferential equation numerically
%% SUMMARY
% Language : Matlab 2008a;
% Authors : Autar Kaw;
% Mfile available at
% http://numericalmethods.eng.usf.edu/blog/odetest.m;
% http://numericalmethods.eng.usf.edu/blog/odestate.m;
% Last Revised : October 22, 2009;
% Abstract: This program shows you how to solve an ODE
% numerically using the ode45 MATLAB routine
% .
clc
clear all
clf
% The inputs are
% 1) The ordinary differential equation
% 2y"+3y'+5y=7*exp(-x), y(0)=11, dy/dx(0)=13
% is entered in state variable form in the
% function odestate available at
% http://numericalmethods.eng.usf.edu/blog/odestate.m
% 2) The outputs are required between x=0 and x=17
% hence entered as [0 17]
% 3) The initial conditions are y(0)=11 and dy/dx(0)=13
% hence entered as [11 13]
% The outputs are
% X= array of x values between 0 and 17
% Y= matrix of 2 columns;
% first column is the y(x)
% second column is dy/dx(x)
[X,Y]=ode45(@odestate,[0 17],[11 13]);
% plotting y(x) vs x
figure (1)
xlabel('x');
ylabel('y');
title('y vs x');
plot(X,Y(:,1),'-');
% plot dy/dx(x) vs x
figure (2)
xlabel('x');
ylabel('dy/dx');
title('dy/dx vs x');
plot(X,Y(:,2),'-');