MATLAB: ex4

← ChE 555: Applied Mathematics & Modeling for Chemical Engineers

echo off;
clc;
clear all;
close all;

% Initial value of indepemdent variable (t0)
% Final value of independent variable (tf)
% Initial value of dependent variable (y0)
% Integration error tolerance (tol)
t0 = 0;
tf = 1;
z0 = [0 0.5871 0 0.0228];

% Define the integration options
% see ode23 help
options = odeset('RelTol',1e-6,'AbsTol',[1e-8],'Stats','on');

% Integrate by ODE45 the derivative functions
% defined in file EX4F.M and assign the
% solution vector to maxrix [t,z]
[t,z] = ode45 ('ex4f',[t0 tf],z0,options);

% Plot the numerical solution vector [t,z]
figure
plot(t,z(:,1),'r-');
hold on
plot(t,z(:,3),'b-');
title('ChE585 EXAMPLE-4'); grid;
xlabel('x-axis'); ylabel('y-axis');
text(0.1,0.85,'red: z(1)=x, numerical');
text(0.1,0.75,'blue: z(3)=y, numerical');
16 successful steps
0 failed attempts
97 function evaluations

EX4 01

Published with MATLAB® 7.0