Hello all,
I've been trying for a while to get the V vector in the euler's method for solving and IVP code that I made below to give out the 6 elements in one vector not separately like it is doing. I have tried moving it around and adding or removing the ; at the end and that either takes it away completely or just gives me the last entry. I would greatly appreciate any help.
function m = eulersmethod(n,t0,t1,w0,f,q)h=(t1-t0)/n;t(1)=t0;w(1)=w0;v=[];V=[];for i=1:nt(i+1)=t(i)+h;w(i+1)=w(i)+h*f((t(i)),(w(i)));endfor i=1:n+1y=q(t0+(i-1)*h);if i<=n+1i=i+h;endV=[y]endv=[t',w'] end
output code
fheulersmethod(5,1,2,0,fhf,fhq)V = 0V = 0.866642535759602V = 2.620359551235833V = 5.720961525596339V = 10.793624660490639V = 18.683097081886419v = 1.000000000000000 0 1.200000000000000 0.543656365691809 1.400000000000000 1.681068828003871 1.600000000000000 3.751012594436661 1.800000000000000 7.224718344336123 2.000000000000000 12.750382866683738
Best Answer