Effacer les filtres
Effacer les filtres

Euler method for vectors?

3 vues (au cours des 30 derniers jours)
qwerty ed
qwerty ed le 8 Avr 2015
Modifié(e) : James Tursa le 8 Avr 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')

Réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by