Array don't store value?

2 ビュー (過去 30 日間)
Khang Nguyen
Khang Nguyen 2021 年 10 月 17 日
編集済み: Stephen23 2021 年 10 月 17 日
I tried to use improve euler method but they array only start the starting value doesn't store the rest of the estimation. Only plot one point intead of going from -0.5 to pi.
f = @(t,y) y*tan(t) + sin(t);
y01 = -0.5;
t01 = 0;
t11 = pi;
h=0.1;
n = linspace(t01,t11,h);
t = (1:length(n));
y = (1:length(n));
y(1) = y01;
t(1) =t01;
for i = 1:(numel(n)-1)
t(i+1) = t(i)+h;
yp = y(i)+h*f(t(i),y(i));
y(i+1) = y(i)+h/2 * (f(t(i),y(i))+f(t(i+1),yp));
end
plot(t,y,"x");

採用された回答

Stephen23
Stephen23 2021 年 10 月 17 日
編集済み: Stephen23 2021 年 10 月 17 日
Replace
n = linspace(t01,t11,h); % Read its help to know why your useage is incorrect.
with
n = t01:h:t11;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by