11.07.2015 Views

Introduction to MATLAB 7 for Engineers - The University of Jordan

Introduction to MATLAB 7 for Engineers - The University of Jordan

Introduction to MATLAB 7 for Engineers - The University of Jordan

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Lecture 9 Computer Applications 0933201 Chapter 8Differential equations: Free and <strong>to</strong>tal step response <strong>of</strong> theequation dy/dt+y=f(t), where =0.1, f(t)=10 & y(0)=2. Figure 8.4–11- <strong>The</strong> freeresponsesolution is:y(t)=y(0)e -t/2- <strong>The</strong> <strong>for</strong>cedresponsesolution is:y(t) =M (1 - e -t/ )<strong>The</strong> <strong>to</strong>talsolution are1 + 2.Z.R.K8-13More? See pages 483-485.Numerical Methods <strong>for</strong> Differential EquationsLet dy/dt = –10y, y(0) = 2. and 0 t 0.5.<strong>The</strong> true solution is y(t) = 2 e -10t .<strong>The</strong> following script file solves and plots thesolution by using Euler method.r = -10; delta = 0.02; y(1) = 2; %?!k=0;<strong>for</strong> time = [delta:delta:0.5] %?!k = k + 1;y(k+1) = y(k) + r*y(k)*delta;endt = [0:delta:0.5]; % <strong>for</strong> true solution.y_t = 2*exp(-10*t); % true solution.plot(t,y,’o’,t,y_t),xlabel(‘t’), ...ylabel(‘y’)Z.R.K8-15Euler method solution <strong>for</strong> the free response <strong>of</strong>dy/dt = –10y, y(0) = 2. Figure 8.5–1Let dy/dt = –10y, y(0) = 2. and 0 t 0.5.<strong>The</strong> true solution is y(t) = 2 e -10t .<strong>The</strong> following script file solves and plots thesolution by using Modified Euler method.r = -10; delta = 0.02; y(1) = 2; k=0;<strong>for</strong> time = [delta:delta:0.5] %?!k = k + 1;x(k+1) = y(k) + r*y(k)*delta;y(k+1) = y(k) + r*y(k)*delta/2 ...+ r*x(k+1);endt = [0:delta:0.5]; % <strong>for</strong> true solution.y_t = 2*exp(-10*t); % true solution.plot(t,y,’o’,t,y_t),xlabel(‘t’), ...ylabel(y’)Z.R.K Z.R.K8-158-16More? See pages 490-492.Modified Euler solution <strong>of</strong> dy/dt = –10y, y(0) = 2. Figure 8.5–3Z.R.K8-17<strong>The</strong> ode solvers.When used <strong>to</strong> solve the first order Ordinarydifferential equation dy/dt = f (t, y), the basicsyntax is (using ode23 or ode45 as theexample):[t,y] = ode23(’ydot’, [t_span], y0)where ydot is the name <strong>of</strong> the function filewhose inputs must be t and y and whoseoutput must be a column vec<strong>to</strong>r representingdy/dt; that is, f (t, y). <strong>The</strong> number <strong>of</strong> rows in thiscolumn vec<strong>to</strong>r must equal the order <strong>of</strong> theequation.Z.R.K8-18More? See pages 496-499.Z.R.K. 2008 Page 3 <strong>of</strong> 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!