I am getting an error, can someone help me please.

댓글 수: 3

Ameer Hamza
Ameer Hamza 2020년 10월 7일
What is the error?
John D'Errico
John D'Errico 2020년 10월 7일
When you have an error, please report the ENTIRE error message, thus everything in red. Doing so will often help us to immediately know what you did wrong.
Ibrahim Butt
Ibrahim Butt 2020년 10월 7일

댓글을 달려면 로그인하십시오.

답변 (1개)

Alan Stevens
Alan Stevens 2020년 10월 7일

0 개 추천

Apart from the fact that you forgot to put "end" at the end of the function (the "end" of the "for" loop doesn't count), there is nothing wrong with it.

댓글 수: 3

Ibrahim Butt
Ibrahim Butt 2020년 10월 7일
Alan Stevens
Alan Stevens 2020년 10월 7일
You have written it as a function. You need to call the function from a script, passing it a handle to F, and values of the other arguments.
Like this:
F = @(t,y) y + t; % Define your dy/dt function
y0 = 1; % Initial condition
t0 = 0;
tfinal = 2;
h = (tfinal-t0)/100;
yout = ode1(F,t0,h,tfinal,y0);
plot(t0:h:tfinal,yout),grid
xlabel('t'),ylabel('y')
function yout = ode1(F,t0,h,tfinal,y0)
% ODE1 A simple ODE solver.
% yout = ODE1(F,t0,h,tfinal,y0) uses Euler's
% method with fixed step size h on the interval
% t0 <= t <= tfinal
% to solve
% dy/dt = F(t,y)
% with y(t0) = y0.
% Copyright 2014 - 2015 The MathWorks, Inc.
y = y0;
yout = y;
for t = t0 : h : tfinal-h
s = F(t,y);
y = y + h*s;
yout = [yout; y];
end
end

댓글을 달려면 로그인하십시오.

카테고리

질문:

2020년 10월 7일

댓글:

2020년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by