python牛顿法解非线性方程组_牛顿法解非线性方程组的MATLAB程序

展开全部

Newton's method is the classic algorithm for finding roots of functions. The breif introduction is written below.

resize,m_lfit,w_600,h_800,limit_1

The analytic solution is

resize,m_lfit,w_600,h_800,limit_1

The code isclear all

x = zeros(1,2);

f = zeros(1,2);

tol = 1E-7;

invJ = zeros(2,2);

x(1) = 0.23;

x(2) = 0.69;

for n = 1:1:1E4

f(1) = x(1)+85.4/x(2)-1;

f(2) = x(1)-10/x(2);

invJ(1,1) = 10/95.4;

invJ(1,2) = 85.4/95.4;

invJ(2,1) = -x(2)^2/95.4;

invJ(2,2) = x(2)^2/95.4;

xn = x'-invJ*f';

if (abs(x(1)-xn(1))/abs(xn(1)) < tol ...

&& abs(x(2)-xn(2))/abs(xn(2)) < tol)

fprintf('The maximum number of iterations is %d\n', n)

disp('The solution within tolerance 1E-7 is')

disp(xn')

return;

end

x = xn';

end

disp('The solution did not converge to x-axis')

The generated result is

resize,m_lfit,w_600,h_800,limit_1