Download presentation

Presentation is loading. Please wait.

Published byIrving Simco Modified about 1 year ago

1
function [x,niter]=gausseidel(A,b,e,N,x0) n=length(b); x=x0; xk=x0; for niter=1:N for i=1:n; Sum1=A(i,1:i-1)*x(1:i-1); Sum2=A(i,i+1:n)*xk(i+1:n); x(i)=(1/A(i,i))*(b(i)-Sum1-Sum2); end if ((x-xk)'*(x-xk)/(x'*x))

2
function [x,i]=newton(foncjac,e,N,x0) x=x0; for i=1:N [F,J]=foncjac(x); h=-J\F // on resout Jh=-F x=x+h; if ((h'*h)/(x'*x+%eps)

3
function [F,J]=foncjac2(v) alpha=5; betta=5; deff('x=g(v)','x=10*v/(1+v)'); deff('x=g1(v)','x=10/((1+v)^2)'); n=length(v); x=linspace(0,1,n); F=zeros(n-1,1); d=zeros(n-1,1); h=1/n; F(1)=-alpha+2*v(1)+h*h*g(v(1))-v(2)-h^2*(-x(1)*(x(1)-1)); for i=2:n-2 F(i-1)=-v(i-1)+2*v(i)+h^2*g(v(i))-v(i+1)-h^2*(-x(i)*(x(i)-1)); end F(n-1)=-v(n-3)+2*v(n-2)+h^2*g(v(n-2))-betta-h^2*(-x(n-2)*(x(n-2)-1)); d=2+h^2.*g1(v(1:n-1)); J=diag(-1*ones(n-2,1),-1)+diag(-1*ones(n-2,1),1)+diag(d); endfunction

4
function [x,i]=newton(foncjac,e,N,x0) x=x0; for i=1:N [F,J]=foncjac(x); h=[0;-J\F;0] // on resout Jh=-F x=x+h; if ((h'*h)/(x'*x)

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google