Newton Raphson loop for backward Euler
显示 更早的评论
Dear all,
I would like to use Newton-Raphson method with backward Euler to meet a specific tolerance. How to change the loop below to get it?
% time step
h = (t_final - t_init)/n; % with n number of time steps
% vectors
t = [tinit zeros(1,n)]; % time
y = [yinit zeros(1,n)]; % solution
% Backward Euler loop
for i = 1:n
t(i+1) = t(i) + h;
y_temp = y(i) + h(f(t(i), y(i)));
y(i+1) = y(i) + hf(t(i+1), y_temp);
end
I would do something like:
for i = 1:n
error = 1;
tolerance = 1e-6;
t(i+1) = t(i) + h;
y_temp = y(i) + h(f(t(i), y(i)));
while error >= tolerance
y(i+1) = y(i) + hf(t(i+1), y_temp);
error = abs(y(i+1) - y_temp) % (local) absolute error
y_temp = y(i+1);
end
end
Is this the correct approach? Could someone give an hint? Thanks in advance.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Newton-Raphson Method 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!