% % Exempel programm för att lösa ekvationssystemet % % x1 + 2(x2) - 2 = 0 % % (x1)^2 + 4(x2)^2 - 4 = 0 % % clear all fel = 0.000000001 ; global k k=0.4; N=40; y1=-4:1/N:4; y2=y1; [x1,x2]=meshgrid(y1,y2); f1=x1+2*x2-2; f2=x1.^2+4*x2.^2-4; hold off contour(x1,x2,f1,[0,0],'b'); hold on contour(x1,x2,f2,[0,0],'r'); [X1,X2]=ginput(1); F1 = X1+2*X2-2 ; F2 = X1^2+4*(X2^2)-4; while ( abs(F1) > fel | abs(F2)> fel ) Jacobi=[1, 1; 2*X1, 8*X2 ]; F1 = X1+2*X2-2 ; F2 = X1^2+4*X2^2-4; Next= - Jacobi\[F1;F2] + [X1;X2] X1=Next(1); X2=Next(2) ; plot ( X1,X2,'*'); end