MATLAB: Can anyone help me in plotting the graph for this euler’s method question

euler's method

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

Best Answer

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)