lsqcurvefit拟合出错。

新手,但从网上查阅了大量帖子和例子,仍不得要领,请高手指教!
(1)程序如下:
clear all;clc
x=[0.564513908,0.504509777,0.485644451,0.4723561,0.464679152,0.453456348]
y=[1.021110196,1.470398683,2.001375985,2.614042103,3.308397036,4.084440786]
a0=[-1,1,-2];%初始值
f=@(a,x)(a(1)+a(2).*x)./(1+a(3).*x);
[a,resnorm] = lsqcurvefit('f',a0,x,y);
a
plot(x,y,'r*',x,f(a,x))
(2)执行结果如下:
x =
0.5645 0.5045 0.4856 0.4724 0.4647 0.4535
y =
1.0211 1.4704 2.0014 2.6140 3.3084 4.0844
错误使用 lsqcurvefit (line 247)
Function value and YDATA sizes are not equal.
出错 e_fit (line 8)
[a,resnorm] = lsqcurvefit('f',a0,x,y);
(3)尝试了在.M文件中定义函数f,错误类型一样。
(4)疑问①x,y矩阵命名一致,为什么会出这样的错误?②isqcurvefit函数都要注意哪些问题?
ps:我用的程序版本是32位R2014a。
谢谢。

 Respuesta aceptada

nunilao
nunilao el 16 de Mayo de 2023

0 votos

试试[a,resnorm] = lsqcurvefit(f,a0,x,y);

Más respuestas (0)

Categorías

Más información sobre Matrix Computations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Mayo de 2023

Respondida:

el 16 de Mayo de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!