can anyone help me in plotting the graph for this euler's method question?

clear all
clc
f=@(t,v)9.81-(7/2125)*v^2;
t0=0;
v0=0;
tn=20;
h=2;
fprintf('\n t v ');
while t0<=tn
fprintf('\n%4.3f %4.3f ',t0,v0); %values of x and y
v1=v0+h*f(t0,v0);
t1=t0+h;
t0=t1;
v0=v1;
end

 채택된 답변

KSSV
KSSV 2020년 11월 3일
편집: KSSV 2020년 11월 4일
clear all
clc
f=@(t,v)9.81-(7/2125)*v^2;
t0=0;
v0=0;
tn=20;
h=2;
t = t0:h:tn ;
v1 = zeros(size(t)) ;
v1(1) = v0 ;
for i = 2:length(t)
v1(i)=v1(i-1)+h*f(t(i),v1(i-1));
fprintf('\n%4.3f %4.3f\n ',t(i),v1(i)); %values of x and y
end
2.000 19.620 4.000 36.704 6.000 47.448 8.000 52.236 10.000 53.879 12.000 54.374 14.000 54.516 16.000 54.556 18.000 54.567 20.000 54.570
plot(t,v1)

댓글 수: 7

tysm bro. this works. but theres a little problem. the graph should be beginning from (x,y)=(0,0) but it starts with coordinates (x,y)=(0,19.62). can you please revise the codes again. i really need help in this for my assignment. i have been trying to get this right for 2days now. ty again
Edited the code...
Unrecognized function or variable 'v'.
Error in eulersmethod2 (line 13)
v1(i)=v(i-1)+h*f(t(i),v(i-1));
-- it is showing this error message
Typo error.......v should be v1... I have edited the answer. Check now.
great. the graph is good. but check your command window. all values of v is 0.000
Huh......edited the answer.....
omg. tysm. this worked finally. tysm bro. i was struggling with this simple math for days. tysm. much appriciate your work here man. ty

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by