Functions returns variable values at each iteration
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohamed Hassan
am 26 Mär. 2016
Bearbeitet: per isakson
am 26 Mär. 2016
So I have this function where I'm calculating the values of the U matrix at each t value (0,1,2,etc.). The problem I'm having is that the function only returns the final value for U, and does not return t value. To illustrate what I'm trying to get, here's an example:
t x y
0 2 1
1 2.6 0.9
2 3.458 0.891
etc.
function [U,t] = IVP(a,b,c)
syms x y h t;
h=c;
x=a;
y=b;
for t=0:1:30
f=[1.2*x-0.6*x*y;0.3*x*y-0.8*y];
u=[x;y];
U=u+h*f;
x=U(1);
y=U(2);
end
end
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 26 Mär. 2016
Bearbeitet: Azzi Abdelmalek
am 26 Mär. 2016
U=[];
for t=0:1:30
f=[1.2*x-0.6*x*y;0.3*x*y-0.8*y];
u=[x;y];
w=u+h*f;
U=[U w];
x=w(1);
y=w(2);
end
t=(0:1:38)'
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!