Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. clear all
  2. close all
  3.  
  4. m=201;
  5. h=1/(m-1);
  6. x=linspace(0,1,m)';
  7. A = toeplitz(sparse([1,2],[1,1],[-2,1]/(h^2),m,1));
  8.  
  9. F=@(u) [u(1);(A*u+ones(m,1)+exp(u))(2:m-1);u(m)-1];
  10. JF=@(u) [[1,zeros(1,m-1)];(A+diag(exp(u)))(2:m-1,1:m);[zeros(1,m-
  11. 1),1]];
  12. u0=ones(m,1); %Starting guess for newton's method
  13. res=-JF(u0)F(u0);
  14. tol=h^2/100;
  15. while (norm(res,inf)>tol)
  16. u0+=res;
  17. res=-JF(u0)F(u0);
  18. end
  19. u0+=res;
  20.  
  21. plot(x,u0,'b-o')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement