Euler Method Loop: Loop values like step size through Euler Method

I am trying to run the for loop below with different values of h. I'm new to matlab and have been struggling to figure out how to do this. Any help is appreciated. Thank you.
k = 0.2;
F = @(t,y) -k*y;
t0 = 0;
h = 1;
tfinal = 5;
y0 = 1;
y = y0; % put y0 into y
yout = y; % put y into the output
for t = t0 : h : tfinal - h
s = F(t,y);
y = y + h*s;
yout = [yout ; y];
end

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

JR
2018 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by