| 查看: 1586 | 回复: 3 | ||||
wsbl金虫 (小有名气)
|
[交流]
Levenberg-Marquardt 算法的例子代码已有3人参与
|
|
#include "stdio.h" #include #include void out(double*p,int n,int m)//输出矩阵 {int i,j; for (i=0;i if ((m*i+j)%m==0) printf("\n" ;printf("%16.8f",*(p+m*i+j)); } printf("\n\n" ;} void LM(double *c, double *sigma, int N, double sigma_H2O,double r[3]) { int i,j,maxtime=100; //如果不收敛,允许的最大迭代次数 double s,snext,det,temp0; double x[]={.5,.5},xnext[2],ep[2]; double f[6]; double f_x1[6]; double f_x2[6]; double m[4]; //矩阵 double temp1[4];//逆矩阵 double temp2[2]; double temp3[2]; double alph,beita; j=0; for (i=0;i f_x1=sigma_H2O*log(1+c/x[1]); f_x2=-sigma_H2O*x[0]*c/(x[1]*x[1])/(1+c/x[1]); } s=.0; for (i=0;i temp0=.0; for (i=0;i m[0]=temp0; temp0=.0; for (i=0;i m[1]=temp0; m[2]=temp0; temp0=.0; for (i=0;i m[3]=temp0; //out(m,2,2);//到此步正确。 alph=(fabs(*m)+fabs(*(m+3)))/2; //printf("%8.5e\n",alph); beita=2.0; m[0]=m[0]+alph; m[3]=m[3]+alph; //out(m,2,2);//到此步正确。 det=1.0/(m[0]*m[3]-m[1]*m[2]); //printf("迭%15.10f\n",det); temp1[0]=det*m[3]; temp1[1]=-det*m[1]; temp1[2]=-det*m[1]; temp1[3]=det*m[0]; //out(temp1,2,2);//到此步正确。 //temp2=mult(temp,f,2,N,1); temp0=.0; for (i=0;i temp2[0]=temp0; temp0=.0; for (i=0;i temp2[1]=temp0; //out(temp2,2,1);//到此步正确。 //temp3=mult(temp1,temp2,2,2,1); temp0=.0; for (i=0;i<2;i++) { temp0=temp0+temp1*temp2; } temp3[0]=temp0; temp0=.0; for (i=0;i<2;i++) { temp0=temp0+temp1[2+i]*temp2; } temp3[1]=temp0; //out(temp3,2,1);//到此步正确。 xnext[0]=x[0]-temp3[0]; xnext[1]=x[1]-temp3[1]; //out(xnext,2,1);//到此步正确。 snext=0; for (i=0;i snext=snext+f*f; } //printf("%8.5e",snext);//到此步正确。 ep[0]=xnext[0]-x[0]; ep[1]=xnext[1]-x[1]; //out(ep,2,1);//到此步正确。 while (((fabs(ep[0])+fabs(ep[1]))/2)>1.0e-6 && j if (snext>=s) alph=alph*beita; else alph=alph/beita; //printf("%8.3f\n",(float)j); x[0]=xnext[0]; x[1]=xnext[1]; s=snext; for (i=0;i f_x1=sigma_H2O*log(1+c/x[1]); f_x2=-sigma_H2O*x[0]*c/(x[1]*x[1])/(1+c/x[1]); } s=.0; for (i=0;i temp0=.0; for (i=0;i m[0]=temp0; temp0=.0; for (i=0;i m[1]=temp0; m[2]=temp0; temp0=.0; for (i=0;i m[3]=temp0; m[0]=m[0]+alph; m[3]=m[3]+alph; //out(m,2,2);//到此步正确。 det=1.0/(m[0]*m[3]-m[1]*m[2]); //printf("迭%15.10f\n",det); temp1[0]=det*m[3]; temp1[1]=-det*m[1]; temp1[2]=-det*m[1]; temp1[3]=det*m[0]; //out(temp1,2,2);//到此步正确。 //temp2=mult(temp,f,2,N,1); temp0=.0; for (i=0;i temp2[0]=temp0; temp0=.0; for (i=0;i temp2[1]=temp0; //out(temp2,2,1);//到此步正确。 //temp3=mult(temp1,temp2,2,2,1); temp0=.0; for (i=0;i<2;i++) { temp0=temp0+temp1*temp2; } temp3[0]=temp0; temp0=.0; for (i=0;i<2;i++) { temp0=temp0+temp1[2+i]*temp2; } temp3[1]=temp0; //out(temp3,2,1);//到此步正确。 xnext[0]=x[0]-temp3[0]; xnext[1]=x[1]-temp3[1]; //out(xnext,2,1);//到此步正确。 snext=0; for (i=0;i snext=snext+f*f; } ep[0]=xnext[0]-x[0]; ep[1]=xnext[1]-x[1]; } r[0]=xnext[0]; r[1]=xnext[1]; r[2]=(double)j; } void main() { //double p[] = {0.02,0.04,0.08,0.12,0.16,0.2,0.24,0.28};//mol/L //double q[] = {0.06810,0.06442,0.0601,0.05678,0.05467,0.05237,0.05108,0.05025};//N/m double p[] = {0.02,0.04,0.08,0.12,0.16,0.2}; double q[] = {0.06810,0.0644,0.0601,0.0568,0.0547,0.0524}; double r[3]; LM(p,q,6,0.07197,r); printf("迭代次数:%5.0f\n",r[2]); if (r[2]<100) { printf("\n希什科夫模型sigma_H2O-sigma_H2O*a*ln(1+x/b)中\n\n参数a的最优值为:%9.9f\n",r[0]); printf("\n参数b的最优值为:%9.9f\n\n",r[1]); } else printf("\n用Levenberg法失败\n\n" ;for(int i=0;i<1;i++)//延时几秒。 { printf("按回车键结束程序:" ;getchar(); } } |
» 收录本帖的淘帖专辑推荐
软件学习 |
» 猜你喜欢
到新单位后,换了新的研究方向,没有团队,持续积累2区以上论文,能申请到面上吗
已经有7人回复
申请2026年博士
已经有5人回复
天津工业大学郑柳春团队欢迎化学化工、高分子化学或有机合成方向的博士生和硕士生加入
已经有5人回复
寻求一种能扛住强氧化性腐蚀性的容器密封件
已经有6人回复
2025冷门绝学什么时候出结果
已经有7人回复
请问有评职称,把科研教学业绩算分排序的高校吗
已经有6人回复
Bioresource Technology期刊,第一次返修的时候被退回好几次了
已经有7人回复
请问哪里可以有青B申请的本子可以借鉴一下。
已经有4人回复
请问下大家为什么这个铃木偶联几乎不反应呢
已经有5人回复
康复大学泰山学者周祺惠团队招收博士研究生
已经有6人回复
» 本主题相关价值贴推荐,对您同样有帮助:
Visual C++ CAD应用程序开发技术源代码(基于OPenGL技术开发的)
已经有76人回复
Levenberg-Marquardt算法能否用于计算1范数定义下的最小值问题?
已经有5人回复
求解一元三次方程
已经有8人回复
求助,自己编代码实现别人的算法,可以申请软件著作权吗
已经有4人回复
求助神经网络 ---Levenberg-Marquardt算法
已经有6人回复
基于L-M算法的BP神经网络
已经有3人回复
【求助】Levenberg-Marquardt法和LBFGS拟牛顿法,求C++版源码及使用方法
已经有3人回复
【求助】MATLAB中BP神经网络的训练算法具体是怎么样的?
已经有5人回复
2楼2011-10-16 07:18:24
lrs2008
木虫 (正式写手)
观天
- 应助: 7 (幼儿园)
- 金币: 3457.1
- 散金: 5505
- 红花: 13
- 帖子: 424
- 在线: 251.9小时
- 虫号: 746075
- 注册: 2009-04-11
- 性别: GG
- 专业: 计算机应用技术

3楼2011-10-16 09:21:30
lingshuning
木虫 (职业作家)
- 应助: 89 (初中生)
- 金币: 1320.9
- 散金: 3426
- 红花: 63
- 帖子: 3433
- 在线: 287.6小时
- 虫号: 1515504
- 注册: 2011-11-29
- 性别: GG
- 专业: 工业工程与管理

4楼2011-12-03 19:18:50













;
回复此楼