Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- close all
- m=201;
- h=1/(m-1);
- x=linspace(0,1,m)';
- A = toeplitz(sparse([1,2],[1,1],[-2,1]/(h^2),m,1));
- F=@(u) [u(1);(A*u+ones(m,1)+exp(u))(2:m-1);u(m)-1];
- JF=@(u) [[1,zeros(1,m-1)];(A+diag(exp(u)))(2:m-1,1:m);[zeros(1,m-
- 1),1]];
- u0=ones(m,1); %Starting guess for newton's method
- res=-JF(u0)F(u0);
- tol=h^2/100;
- while (norm(res,inf)>tol)
- u0+=res;
- res=-JF(u0)F(u0);
- end
- u0+=res;
- plot(x,u0,'b-o')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement