function [p,res_p]=test_LM(p0,xdata,ydata)
% this m-file is used to test the simplest Levenberg-Marquardt method
% Reference:
% A Brief Description of the Levenberg-Marquardt Algorithm Implemented by
% levmar
% Ref: http://www.ics.forth.gr/~lourakis/levmar
% Edited by LUXP
% Date: 2011.1.17
% Initial the sample: f(x)=acos(x)+bsin(x) for given x=1,2,3,fx=fx1,fx2,fx3
% and initial test p0=[0,0]'
% Minimizing ||fx-f(a,b)||^2 to compute the optimizal a,b by LM algorithm
%fx=fun_LM(x,p); %given x and fx values
% define the threshold parameters:
kmax=100; % the largest iteration steps
eps1=10^(-15); %check whether the ||g||_inf is close to 0
eps2=10^(-15); % check
eps3=10^(-15); % check
tao=10^(-3);
factor=2; %the diagnal values of J'J is enlargered by factor
%Initial values
p=p0;
J=Jacobi_LM(p,xdata); %Jacobi matrix of fx on parameters p
A=J'*J;
res_p=ydata-fun_LM(p,xdata); %residual of p: ydata-f(x,p)
g=J'*res_p; %solve the linear equation: Ndp=g to find dp:delta P:change of P;
% main iteration steps
if norm(g,inf)<=eps1
disp('Jacobi*residual=0, the initial p is wanted!');
else
eye_mu=eye(size(A));
mu=tao*max(diag(A));
for k=1:kmax
A=A+mu.*eye_mu;
dp=A\g;
if norm(dp)<=eps2*norm(p)
disp('delta P is large less than P, the p is wanted!' );
break;
end
p_new=p+dp;
rou=(norm(res_p)^2-norm(ydata-fun_LM(p_new,xdata))^2)/(dp'*(mu*dp+g));
if rou>0
p=p_new;
J=Jacobi_LM(p,xdata);
A=J'*J;
res_p=ydata-fun_LM(p,xdata);
g=J'*res_p;
if (norm(g,inf)<=eps1) || (norm(res_p)^2<=eps3)
disp('norm g is less then eps1 or norm of res_p less than eps3');
break;
end;
mu=mu*max(1/3,1-(2*rou-1)^3);
factor=2;
else
mu=mu*factor;
factor=factor*2;
end
end
end
p=p;
res_p=res_p;
end
function y=fun_LM(p,x)
y=p(1).*cos(x)+p(2).*sin(x);
end
function J=Jacobi_LM(p,x)
J=cos(x);
J=[J,sin(x)];
end

JaniceLu
- 粉丝: 109
最新资源
- 01Studio CanMV K230开发板 3路摄像头显示,默认外接HDMI显示器
- yolov13夜间场景车辆检测权重+标注好的夜间场景车辆检测数据集+pyqt界面
- 新能源锂电池项目中欧姆龙NJ PLC程序设计:梯形图与ST语言混合编程及电子凸轮应用 精选版
- 基于Maxwell电磁仿真的变压器设计与铁芯损耗计算优化方法 - 电磁仿真
- 跨领域条件下的目标识别与检测研究
- YOLOv13夜间场景车辆检测,包含训练好的夜间场景道路上车辆检测权重yolov13-main-sts-dark-car-detection-data.zip
- 苏州大学电力电子技术课程仿真实验项目-电力电子变换器仿真开关电源设计逆变器控制PWM调制技术Saber软件应用电路拓扑分析功率半导体器件特性研究-用于ELEA2015课.zip
- YOLOv12夜间场景车辆检测,包含训练好的夜间场景道路上车辆检测权重+pyqt界面
- 西门子S7-300PLC与TP900触摸屏在污水处理中的自动化控制及博途V15.1集成应用
- YOLOv12夜间场景车辆检测,包含训练好的夜间场景道路上车辆检测权重,以及PR曲线,loss曲线等等
- 《基于欧姆龙NJ501-1400的锂电池铝壳全自动二次注液机:分布式总线控制与高效转盘式结构设计》
- 基于SCL语言的RS485通讯程序实现:变频器正反转及停止操作与校验码优化 · PLC编程 全面版
- YOLO 算法在目标检测领域的应用解析
- 新能源PLC程序:欧姆龙NJ系列,多轴控制与凸轮同步的完整面向对象编程资料
- 基于OpenGLES的iOS平台32BGRA图像渲染与旋转处理工具-支持32位BGRA格式图像渲染-纹理旋转功能-集成YUV420P格式支持-专为视频处理优化的高性能图形渲染框架-.zip
- 电力系统源荷不确定性优化调度模型研究:MATLAB与YALMIP联合应用实现非线性目标的线性转化,引入模糊机会约束与碳交易策略 - 碳交易 全面版
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


