I do not know how to fix this problem (code below)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
JoshT_student
le 7 Juin 2018
Modifié(e) : Walter Roberson
le 7 Juin 2018
%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:101
fprintf(fid, ' %6.2f %10.2f %10.2f %10.2 \n' t1(i), y1(i), y2(i), y3(i)); %HERE
end
fclose(fid);
plot(t1, Y(:,1), t1, Y(:,2), '-.', t1, Y(:,3), '--'),
xlabel('t'), ylabel('Y(1), Y(2), Y(3)')
title('Y vs. t');
grid
text(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
1 commentaire
Steven Lord
le 7 Juin 2018
Please copy and paste the full text of the error message you receive (all the red text) into a comment. Don't paraphrase, post it exactly as it appears in the Command Window.
Réponse acceptée
Aquatris
le 7 Juin 2018
You are missing a comma (,) before the t1 there. You are also missing a comma at line "plot(t1,.." before the "title".
Also in the code you provide, you do not give "@dydt3" function any further mistakes cannot be found.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!