Azzera filtri
Azzera filtri

Euler method for vectors?

3 visualizzazioni (ultimi 30 giorni)
qwerty ed
qwerty ed il 8 Apr 2015
Modificato: James Tursa il 8 Apr 2015
Here is code I wrote for computing Euler's method. My question is, how can I make this work for vector inputs? (I have another function that returns a vector equation). Thank you.
EDIT: I'm not sure why the formatting is messed up and I'm not quite sure how to fix it.
_______________________________________
function euler(func, y0, t0, tf)
% y0 = initial y value
% m = number of spatial discretization points
% t0 = initial time (t0 = 0)
% tf = final time (tf = 4)
h = (2*pi)/32; % define step size
t=t0:h:tf; % time interval
% setting initial y value
y(1) = y0;
% loop using euler's method
for i = 1:length(t)-1
y(i+1) = y(i) + h*(feval(func,t(i)));
end
% print column vectors of t and y
t = t'
y = y'
plot(t,y)
xlabel('time')
ylabel('y')

Risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by