Implementing a Newton-Raphson iteration method
I'm trying to implement a backward Euler Scheme using the Newton Raphson iteration. I understand that with each iteration, one makes an initial guess, calculates the residual and solv开发者_运维百科e for the change. In my case the change is del w. After that I know to add the value to w^m and get an update value for w at the next m iteration. I know to check the convergence of the solution as the iterations go on. The problem I am having is how to implement the time step dt as t=0:Tmax/dt where Tmax is say 10. I'm confused on how the time stepping comes in. I've been trying to figure this out for a while so any help will be appreciated. Thank you!
while Rw(m)>10^-6 % Convergence condition
drdw(m)=(1-2*dt+2*t(n+1)^2*w(m)*dt);
Dw(m)=Rw(m)\drdw(m); %Inverse
w(m+1)=w(m)+Dw(m); %Newton method
Rw(m+1)=(-(w(m)-v(1)-2*w(m)*dt+t(n+1)^2*w(m)^2*dt)); %New Residual value
if Rw(m+1)>10^-6 %Check on the level of convergence
m=m+1;
else
Rw=1; % I was thinking I should make the Residual 1 for the next time step.
break
end
Something is strange in there, a 1st order ODE is of the form dy/dt = f(t,y) yet you have w,v,t,m and n.
You are computing your solution over the time interval (0,T) into a partition with constant step size h:
t0 = 0; tk = hk; tn = T
For this
Try implementing your newton method (using the while conditional as you have above) to solving the above as a separate function and then integrate it into your euler over the steps
1 to n where n = Tmax/h.
精彩评论