matlab中指数模型函数拟合

已知点x=[0,100,200,300,400,500],y=[1,0.62,0.40,0.21,0.18,0.12],并且已知数学模型为y=exp(a*x^2+b*x),请问怎么拟合这些数据点得到拟合曲线并且得到系数a和b呢?

clc

clear

close all

x=[0,100,200,300,400,500];

y=[1,0.62,0.40,0.21,0.18,0.12];

xx=x(2:end);

yy=y(2:end);

z=log(yy)./xx;

c=polyfit(xx,z,1);

a=c(1)

b=c(2)

ny=exp(a*x.^2+b*x);

plot(x,y,'r*')

hold on

ezplot(['exp(',num2str(a),'*x.^2+',num2str(b),'*x)'],[0 500 min(y) max(y)])

xlabel('x')

ylabel('y')

legend('原始数据散点图','拟合后函数曲线图')



运行结果


a =


    1.374119463200583e-006



b =


  -0.005030534633423

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-07-25
x=readtable('练习数据.xlsx','sheet','旅客数量');
lny=log(x.amount);
t=[1:1:height(x)]';
data=table(lny,t);
m=fitlm(data,'lny ~ t');
c=exp(m.Coefficients.Estimate);
相似回答