Borrar filtros
Borrar filtros

Euler method for vectors?

3 visualizaciones (últimos 30 días)
qwerty ed
qwerty ed el 8 de Abr. de 2015
Editada: James Tursa el 8 de Abr. de 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')

Respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by