How can I change this code to euler backward method? (implicit method)
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
f = @(t,y) -100000*y + 99999*exp(-t);
t0 = 0; y0 =0;
h = 0.01; tn = 2;
n = (tn-t0)/h;
t(1)=t0; y(1)=y0;
for i=1:n
    t(i+1) = t(i) + h;
    y(i+1) = y(i) + (f(t(i),y(i))*h);
end
plot(t,y)
0 个评论
采纳的回答
  Torsten
      
      
 2022-6-7
        
      编辑:Torsten
      
      
 2022-6-7
  
      f = @(t,y) -100000*y + 99999*exp(-t);
t0 = 0; y0 =0;
h = 0.01; tn = 2;
n = (tn-t0)/h;
t(1)=t0; y(1)=y0;
for i=1:n
    t(i+1) = t(i) + h;
    fun = @(x) x - y(i) - h*f(t(i+1),x);
    y(i+1) = fzero(fun,y(i));
end
plot(t,y)
hold on
exact = @(t) exp(-t)-exp(-100000*t);
plot(t,exact(t))
0 个评论
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


