【问题标题】:matlab - two variables least squares function approximationmatlab - 两个变量最小二乘函数逼近
【发布时间】:2011-05-31 12:42:29
【问题描述】:

我有一个类型的两个变量的函数:y = f(x1,x2) 要近似,我想用最小二乘法来做。

Polyval 和 Polyfit 处理二维函数,这里我需要求解一个三维函数。

提前致谢。

GB

【问题讨论】:

标签: matlab multidimensional-array least-squares


【解决方案1】:

我是这样解决的

A = [x1.^2,x1.*x2,x2.^2,x1,x2,ones(长度(x1),1)]; c=A\y;

yEval = c(1)*x1.^2+c(2)*x1.*x2+c(3)*x2.^2+c(4)*x1+c(5)*x2+c (6);

感谢您的帮助。

问候, G.B.

【讨论】:

    【解决方案2】:

    查看您的函数,您似乎正在使用一个完整的二次响应曲面来拟合。 您可以使用 x2fx 函数来生成所有条款。这里没有什么开创性的,但它可能会更干净一些。您不仅可以使用它来进行 OLS 拟合,还可以使用稳健的方法。 这是我写的一些代码:

    % set up terms for the variables, linear, quadratic, interactive, and constant
    paramVEcomponents= x2fx([MAPkpa,RPM],'quadratic');
    % robust fit using a Talwar weighting function
    [coefs,robuststats]= robustfit(paramVEcomponents(2:6),(CAM2.*TEMPd./MAPkpa),'talwar');
    % generating points for all the data we have based on the new parameters of the response surface
    GMVEhat= paramVEcomponents * coefs;
    

    【讨论】:

    • 我觉得这个答案需要统计工具箱
    猜你喜欢
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 1970-01-01
    • 1970-01-01
    • 2010-12-25
    • 2023-04-04
    相关资源
    最近更新 更多