Euler method table problem.Why my fprintf(y(i+1)) only has the last ans, my y1-y(i+1) is incorrect and how to let the table be tidy?
4 次查看(过去 30 天)
显示 更早的评论
h=0.2;
x=0:h:1;
y=zeros(size(x));
y(1)=0;
n=numel(y);
y1=exp(x)-x-1;
fprintf('xn \t yn\t y(xn)\t error\n ');
for i=1:n-1
f = x(i)+y(i);
y(i+1) = y(i) + h * f;
end
fprintf('%f\t %f\t %f\t %f\n',x,y(i+1),y1,y1-y(i+1));
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!