%ode45_ex.m
%This program solves a system of 3 differential equations
%by using ode45 function
%y1'=y2*y3*t, y2'=-y1*y3, y3'=-0.51*y1*y2
%y1(0)=0, y2(0)=1.0, y3(0)=1.0
clear; clc;initial=[0.0 1.0 1.0]tspan=0.0:0.1:10.0;options=odeset('RelTol', 1.0e-6, 'AbsTol', [1.0e-6 1.0e-6 1.0e-6]);[t, Y]=ode45(@dydt3, tspan, initial, options);P=[t Y];disp(P);t1=P(:,1);y1=P(:,2);y2=P(:,3);y3=P(:,4);fid=fopen('output.txt','w');fprintf(fid,' t y(1) y(2) y(3) \n');fprintf(fid, '------------------------------\n');for i=1:2:101fprintf(fid, ' %6.2f %10.2f %10.2f %10.2 \n' t1(i), y1(i), y2(i), y3(i)); %HERE
endfclose(fid);plot(t1, Y(:,1), t1, Y(:,2), '-.', t1, Y(:,3), '--'), xlabel('t'), ylabel('Y(1), Y(2), Y(3)')title('Y vs. t');gridtext(6.0, -1.2, 'y(1)')text(7.7, -0.25, 'y(2)')text(4.2, 0.85, 'y(3)');
The program keeps saying that something is wrong with the t1. I bolded where it says the problem is.
Thanks for your help
Best Answer