Download presentation
Presentation is loading. Please wait.
Published byIrving Simco Modified over 9 years 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))<e return; else xk=x; end error("LA METHODE DE GAUSS-SEIDEL NE CONVERGE PAS!!!"); endfunction
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)<e) return; end error("LA METHODE DE NEWTON NE CONVERGE PAS!!!"); endfunction function courbe(N) teta=linspace(0,2*%pi,N); x=linspace(-4,2,N); plot(2*cos(teta),2*sin(teta),x,exp(x),'axis','equal'); endfunction function [F,J]=foncjac(x) F(1)=x(1)^2+x(2)^2-4; F(2)=x(2)-exp(x(1)); J=[ 2*x(1) 2*x(2); -exp(x(1)) 1 ]; endfunction
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)<e) return; end error("LA METHODE DE NEWTON NE CONVERGE PAS!!!"); endfunction
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.