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일

0 개 추천

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?
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.

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

카테고리

도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2014년 2월 9일

댓글:

2014년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by