필터 지우기
필터 지우기

Euler method for vectors?

조회 수: 3 (최근 30일)
qwerty ed
qwerty ed 2015년 4월 8일
편집: James Tursa 2015년 4월 8일
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')

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by