Filter löschen
Filter löschen

Euler method for vectors?

3 Ansichten (letzte 30 Tage)
qwerty ed
qwerty ed am 8 Apr. 2015
Bearbeitet: James Tursa am 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')

Antworten (0)

Kategorien

Mehr zu Mathematics 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!

Translated by