Matlab学习手记——非线性方程组求解:牛顿下山法

功能:牛顿下山法求解非线性方程组。

  • 牛顿下山法
function [x, n] = NonLinearEquations_NewtonDown(x0, err)
%{
函数功能:牛顿下山法求解非线性方程组的解;
输入:
  x0:初始值;
  err:精度阈值;
输出:
  x:近似解;
  n:迭代次数;
示例:
clear; clc;
[r, n] = NonLinearEquations_NewtonDown([0 0 0], 1e-6)
%} 
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
x = x0- myfun(x0)/dmyfun(x0);
n = 1;
tol = 1;
while tol > err
    x0 = x;
    tol = 1;
    w=1;
    F1 = norm(myfun(x0));
    while tol >= 0
        x = x0 - w*myfun(x0)/dmyfun(x0);
        tol = norm(myfun(x)) - F1;
        w = w/2;
    end
    tol = norm(x - x0);
    n = n + 1;
    if(n > 1000)
        disp('迭代步数太多,可能不收敛!');
        return;
    end
end

function f = myfun(x)
x1 = x(1);
x2 = x(2);
x3 = x(3);
f(1) = 3*x1 - cos(x2*x3) -1/2;
f(2) = x1^2 - 81*(x2 + 0.1) + sin(x3) + 1.06;
f(3) = exp(-x1*x2) + 20*x3 + 1/3*(10*pi - 3);

function df =dmyfun(x)
x1 = x(1);
x2 = x(2);
x3 = x(3);
df=[3, x3*sin(x2*x3), x2*sin(x2*x3); 2*x1, -81, cos(x3); -x2*exp(-x1*x2), -x1*exp(-x1*x2), 20];

 

评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值