Matlab - 两个变量最小二乘函数逼近

4

我有一个二元函数 y = f(x1,x2) 需要近似,我想使用最小二乘法。

Polyval和Polyfit适用于二维函数,这里需要解决一个三维函数。

谢谢。

G.B.


请查看https://dev59.com/bVLTa4cB1Zd3GeqPdtGg。 - zellus
2个回答

3
我以这种方式解决了它:
A = [x1.^2,x1.*x2,x2.^2,x1,x2,ones(length(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.

0

看你的函数,似乎是在使用完整的二次响应面来拟合。 您可以使用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;

我认为这个答案需要使用统计工具箱。 - KAE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接