Euler Method keep getting an error for tvec=zeros(N+1,1)

4 vues (au cours des 30 derniers jours)
Kristian Torres
Kristian Torres le 2 Juil 2020
Commenté : KSSV le 2 Juil 2020
%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--')

Réponses (0)

Catégories

En savoir plus sur Physics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by