- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 11734 个
- 通用积分
- 2.2450
- 学术水平
- 119 点
- 热心指数
- 115 点
- 信用等级
- 114 点
- 经验
- 8940 点
- 帖子
- 173
- 精华
- 10
- 在线时间
- 30 小时
- 注册时间
- 2006-9-19
- 最后登录
- 2022-11-3
|
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % MATLAB code levenberg-marquardt.m
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % n_of_var -> number of design variables
- % x = [-1.5 1.5] -> starting value of x
- % lambda -> initially set to a large value
- % epsilon1, epsilon2 -> constant used for terminating
- % the algorithm
- % delx -> required for gradient computation
- % f_prev -> function valye at first / previous iteration
- % deriv -> gradient vector
- % sec_deriv -> hessian matrix
- % search -> search direction (vector)
- %
- clear all
- clc
- n_of_var = 2;
- x = [-3 2];
- lambda = 1e3;
- epsilon1 = 1e-7;
- epsilon2 = 1e-7;
- delx = 1e-3;
- f_prev = func_multivar(x);
- fprintf('Initial function value = %7.4f\n ',f_prev)
- fprintf(' No. x-vector f(x) Deriv \n')
- fprintf('__________________________________________\n')
- for i = 1:100
- f_prev = func_multivar(x);
- deriv = grad_vec(x,delx,n_of_var);
- sec_deriv = hessian(x,delx,n_of_var);
- search = -inv(sec_deriv+lambda*eye(length(x)))*deriv';
- x = x + search';
- f = func_multivar(x);
- if f < f_prev
- lambda = lambda/2;
- else
- lambda = 2*lambda;
- end
- if abs(f-f_prev)<epsilon1 || norm(deriv)<epsilon2
- break;
- end
- fprintf('%3d %8.3f %8.3f % 8.3f %8.3f \n',i,x,f,norm(deriv))
- end
- fprintf('__________________________________________\n')
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
复制代码
|
|