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.

 採用された回答

Torsten
Torsten 2015 年 3 月 20 日

0 投票

You use a simple fixed-point iteration to get y(i+1), no Newton-Raphson.
Best wishes
Torsten.

3 件のコメント

Clint_E
Clint_E 2015 年 3 月 20 日
編集済み: Clint_E 2015 年 3 月 20 日
Thanks a lot, so please how would you change it to get Newton-Raphson? Best wishes
Torsten
Torsten 2015 年 3 月 20 日
yold = y(i)+h*f(t(i),y(i));
while error >= tolerance
ynew = yold-(yold-(y(i)+h*f(t(i+1),yold)))/(1-h*df(t(i+1),yold));
error = abs(ynew-yold);
yold=ynew;
end
y(i+1) = ynew;
df is the derivative of f with respect to y.
Best wishes
Torsten.
Clint_E
Clint_E 2015 年 3 月 20 日
Thanks a lot! Best wishes

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

その他の回答 (0 件)

質問済み:

2015 年 3 月 20 日

コメント済み:

2015 年 3 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by