我正在处理由两个数组组成的曲线拟合数据:

t: 1, 3, 4, 7, 8, 10

P: 2.1, 4.6, 5.4, 6.1, 6.4, 6.6

这两个变量之间的关系由P = mt/(b+t)给出。我被告知要通过将方程曲线拟合到数据点来确定常数m和b。这应该通过编写方程的倒数并使用一阶多项式来完成。这是我的代码:
t = [1 3 4 7 8 10];
P = [2.1 4.6 5.4 6.1 6.4 6.6];

p = polyfit(t, t./P, 1);


m = 1/p(1)
b = p(2)*m

tm = 1:0.01:10;
Pm = (m*tm)./(b+tm);

plot(t,P, 'o', tm, Pm)

书中的答案是m = 9.4157b = 3.4418。上面的代码产生m = 8.4807b = 2.6723。我怎么了任何建议将不胜感激。感谢您的时间。

最佳答案

要跟进@David_G的评论,看来您有一个更好的答案。实际上,如果通过MATLAB中的Curve Fitting Toolbox运行数据,则会得到:

General model:
  f(t) = m*t/(b+t)
Coefficients (with 95% confidence bounds):
   b =       2.587  (1.645, 3.528)
   m =       8.448  (7.453, 9.443)

Goodness of fit:
  SSE: 0.1594
  R-square: 0.9888
  Adjusted R-square: 0.986
  RMSE: 0.1996

您的解决方案几乎一样好:
Goodness of fit:
  SSE: 0.1685
  R-square: 0.9881
  Adjusted R-square: 0.9852
  RMSE: 0.2053

而且它们都比本书中的一个要好:
Goodness of fit:
  SSE: 0.404
  R-square: 0.9716
  Adjusted R-square: 0.9645
  RMSE: 0.3178

关于matlab - 使用自定义方程的MATLAB曲线拟合,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16705730/

10-12 18:16