紧急求助!一个matlab编程问题

有公式:y=a(exp(bx)),已知x=4,6,8,12,20,26,36,56,95,240,360,541,2147,12000;对应的y=0.25,0.22,0.... 有公式:y=a(exp(bx)),已知x=4,6,8,12,20,26,36,56,95,240,360,541,2147,12000;对应的y=0.25,0.22,0.2 ,0.18,0.16,0.14,0.12,0.1,0.08,0.06,0.04,0.02,0,0.现要用matlab的非线性最小二乘法求a,b要具体的matlab程序.并画图
本人急用此程序,希望matlab高手指教,万分感谢!!!
这回显示的的结果是??? Undefined function or variable 'nlinfit'.因为刚开始用不怎么会,麻烦了
展开
 我来答
化学工程
2008-04-12 · TA获得超过8900个赞
知道大有可为答主
回答量:2212
采纳率:80%
帮助的人:3340万
展开全部
【补充】也许你的matlab版本低,这样也行,结果一样。
clc;clear
x=[4,6,8,12,20,26,36,56,95,240,360,541,2147];%,12000];
y=[0.25,0.22,0.2 ,0.18,0.16,0.14,0.12,0.1,0.08,0.06,0.04,0.02,0];%,0.];
funy1=inline('a(1)*(exp(a(2)*x))','a','x')
a=nlinfit(x,y,funy1,[0.2 -0.01])
funy2=inline(' b(1)*exp(b(2)*x)+b(3)*exp(b(4)*x)','b','x')
b=nlinfit(x,y,funy2,[0.2 -0.01 0.2 -0.01])
xx=0:x(end);
y1=a(1)*exp(a(2)*xx);
y2=b(1)*exp(b(2)*xx)+b(3)*(exp(b(4)*xx));
plot(x,y,'o',xx,[y1;y2])

【原来的】提供的方程不太好,推荐一个 f(x) = a*exp(b*x) + c*exp(d*x),效果更好。看看对比。

clc;clear
x=[4,6,8,12,20,26,36,56,95,240,360,541,2147];%,12000];
y=[0.25,0.22,0.2 ,0.18,0.16,0.14,0.12,0.1,0.08,0.06,0.04,0.02,0];%,0.];
funy1=@(a,x) a(1)*(exp(a(2)*x))
a=nlinfit(x,y,funy1,[0.2 -0.01])
funy2=@(b,x) b(1)*exp(b(2)*x)+b(3)*exp(b(4)*x)
b=nlinfit(x,y,funy2,[0.2 -0.01 0.2 -0.01])
xx=0:x(end);
y1=a(1)*exp(a(2)*xx);
y2=b(1)*exp(b(2)*xx)+b(3)*(exp(b(4)*xx));
plot(x,y,'o',xx,[y1;y2])

结果:
a =

0.2272 -0.0137

b =

0.1645 -0.0638 0.1135 -0.0030
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式