Euler Method keep getting an error for tvec=zeros(N+1,1)
4 次查看(过去 30 天)
显示 更早的评论
%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--')
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!