Euler Method keep getting an error for tvec=zeros(N+1,1)
Show older comments
%Euler Method
%Used to approximate f'(t,y)=y' y(1)=2
a=1; %left time endpoint
b=2; %right end point
N=10; % number odf steps
alpha=2; %initial condition
h=(b-a)/N;% width of each triangle;
wvec=zeros(N+1,1);%approximation solution vector
yvec=zeros(N+1,1);% real solution vector
tvec=zeros(N+1,1);time %vector
wvec(1)=alpha;
yvec(1)=alpha;
tvec(1)=a;
for i=2:N+1
wvec(i)=wvec(i-1)+h*ftyy(tvec(i-1),wvec(i-1));
tvec(i)=a+(i-1)*h;
yvec(i)=2*tvec(i)+tvec(i)*log(tvec(i));
end
[t,z]=ode45(@ftyy,tvec,alpha);
T=table(tvec,wvec,yvec,abs(wvec-yvec),z,abs(z-yvec));
writetable(T,'EuulerS.xlsx')
plot(tvec,wvec,'r-',tvec,yvec,'b-',t,z,'r--')
1 Comment
KSSV
on 2 Jul 2020
You must specify the error ..
Answers (0)
Categories
Find more on Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!