永发信息网

matlab的nlinfit问题

答案:2  悬赏:40  手机版
解决时间 2021-02-14 06:42
  • 提问者网友:放下
  • 2021-02-13 10:12
a=[1,1,1];
>> r=15:49;
>> b1=[ 0.000010000 0.000160000 0.000840000 0.002390000 0.004150000 0.010370000 0.019870000 0.028860000 0.044920000 0.055200000 0.054620000 0.059010000 0.059650000 0.068670000 0.055330000 0.040070000 0.032520000 0.025670000 0.018140000 0.014650000 0.011940000 0.009660000 0.008380000 0.006950000 0.005590000 0.005320000 0.004050000 0.004600000 0.003400000 0.003210000 0.003420000 0.002950000 0.003690000 0.003750000 0.002660000 ];
>> fun=inline('1/sqrt(2*pi*a(2).^2)*exp(-1/2*(log(r-15)-a(1)).^2/a(2)^2)*a(3)','r','a');
>> ae=nlinfit(t,c,f,a);

程序显示错误:??? Error using ==> nlinfit at 127
MODELFUN should return a vector of fitted values the same length as Y.

然后我简化方程fun=inline('exp(log(r))','r','a'),,还是那个错,,很急大家帮帮忙
r,b1都是35个
最佳答案
  • 五星知识达人网友:梦中风几里
  • 2021-02-13 10:33
我的matlab告诉我这错。
MODELFUN must be a function that returns a vector of fitted values the same size as Y (1-by-35). The model function you
provided returned a result that was 1-by-3.
One common reason for a size mismatch is using matrix operators (*, /, ^) in your function instead of the corresponding
elementwise operators (.*, ./, .^).

如果你还不知道自己哪错了,就试试用fun=inline('exp(log(r))','a','r')再算一下(注意我给你的函数和你写的是不一样的)然后应该就知道了。
全部回答
  • 1楼网友:像个废品
  • 2021-02-13 11:19
%[1 1 1]就是给a(1),a(2),a(3) 参数赋予初值 %程序运行不了是因为你定义的内联函数inline有错,注意t为数组运算符得用点 t=[1790:10:2000]; p=[3.9 5.3 7.2 9.6 12.9 17.1 23.2 31.4 38.6 50.2 62.9 76.0 92.0 106.5 123.2 131.7 150.7 179.3 204.0 226.5 251.4 281.4]; ft=inline('a(1).*a(2)./(a(1)+exp(-a(3).*t).*a(2)-exp(-a(3).*t).*a(1))','a','t'); a=nlinfit(t,p,ft,[1 1 1]) %a = 1.0000 94.7727 1.0000 %但是给出警告,拟合结果不好,得参考帮助设置一下optimset 另外,团idc网上有许多产品团购,便宜有口碑
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯