找回密码
 注册
Simdroid-非首页
查看: 85|回复: 2

求助:曲线拟合的问题

[复制链接]
发表于 2012-4-14 14:53:04 | 显示全部楼层 |阅读模式 来自 浙江杭州
M文件:
function f=examfun(p,x)
f=p(1)*exp(-((x-p(2))/p(3))^2) + p(4)*exp(-((x-p(5))/p(6))^2)+p(7)*exp(-((x-p(8))/p(9))^2) + p(10)*exp(-((x-p(11))/p(12))^2)+p(13)*exp(-((x-p(14))/p(15))^2);
程序入口:
x0=[300,2,1,1900,5,2,-80,6,0,3900,9,3,800,3,1]
xdata=[...]  (略)
ydata=[...]
fun=@examfun
p=lsqcurvefit(fun,x0,xdata,ydata)

错误提示:
??? Error using ==> optim\private\lsqncommon
User supplied function ==> examfun
failed with the following error:
Error using ==> mpower
Matrix must be square.
Error in ==> lsqcurvefit at 165
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...

请问:我的代码哪里出错了?应该怎么修改?谢谢!
发表于 2012-4-14 19:52:03 | 显示全部楼层 来自 湖北武汉
Simdroid开发平台
用点乘试试
回复 不支持

使用道具 举报

发表于 2012-4-14 20:43:03 | 显示全部楼层 来自 北京
至少要给个数据啊。
function f=examfun(p,x)
f=p(1)*exp(-((x-p(2))/p(3)).^2) + p(4)*exp(-((x-p(5))/p(6)).^2)+...
   p(7)*exp(-((x-p(8))/p(9)).^2) + p(10)*exp(-((x-p(11))/p(12)).^2)+...
   p(13)*exp(-((x-p(14))/p(15)).^2);
函数定义中变量之间要用点乘或者点除
clear;clc;
x0=[300,2,1,1900,5,2,-80,6,0,3900,9,3,800,3,1];
xdata=0:0.01:2*pi;
ydata=sin(xdata);
fun=@examfun
p=lsqcurvefit(fun,x0,xdata,ydata)
我给xdata ydata任意赋下值
??? Error using ==> snls at 259
lsqcurvefit cannot continue: user function is returning Inf or NaN values.

Error in ==> lsqncommon at 149
    [xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]=...

Error in ==> lsqcurvefit at 258
[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...

其他我就找不出来了

评分

1

查看全部评分

回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-7-5 12:13 , Processed in 0.032351 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表