help with euler code

6 ビュー (過去 30 日間)
Kyle
Kyle 2014 年 2 月 9 日
コメント済み: Walter Roberson 2014 年 2 月 9 日
i wrote the following matlab( for a euler) code and i can't get it to plot, or provide a figure w. the results. can anyone help?
function [dy] = y(n,to,t,y0)
h=[0.1]
t0=0
y0=1
n=50
h=0.1
t=t0
y=y0
for i=1:n
k=2-exp(-4*t)-2*y
y=y+h*k
t=t+h
plot (t,y)
sprintf('t',' y')
end

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 2 月 9 日
編集済み: Walter Roberson 2014 年 2 月 9 日
After the plot() call, add
hold on
Change your sprintf() line to
fprintf('%.14f %.14f\n', t, y);
  2 件のコメント
Kyle
Kyle 2014 年 2 月 9 日
thanks for your response. this doesn't seem to work, tho. when i plot, ( w. and w.o the code change) i'm getting a blank graph. any thoughts?
Walter Roberson
Walter Roberson 2014 年 2 月 9 日
If you add the "hold on" after the plot() call then the plot is not blank, but the points are not very visible. Try using
plot(t, y, 'r*')
to make the points more visible.

サインインしてコメントする。

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by