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

3 ビュー (過去 30 日間)
Kristian Torres
Kristian Torres 2020 年 7 月 2 日
コメント済み: KSSV 2020 年 7 月 2 日
%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 件のコメント
KSSV
KSSV 2020 年 7 月 2 日
You must specify the error ..

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangePhysics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by