Matlab - approximation of functions with two least squares variables

I have a function of two variables of type: y = f (x1, x2) for approximation, and I would like to use the least squares method for this.

Polyval and Polyfit work with a two-dimensional function, here I need to solve a three-dimensional function.

Thanks in advance.

GB

+4
source share
2 answers

I solved it this way

A = [x1. ^ 2, x1. * x2, x2. ^ 2, x1, x2, units (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);

Thank you for your help.

Regards, GB

+3
source

Looking at your function, it looks like you are using the full square surface of the answer to make it fit. You can use the x2fx function to generate all terms. There is nothing revolutionary here, but it can be a little cleaner. You can also use it not only to install OLS, but also to use reliable methods. Here is the code I wrote:

% 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; 
0
source

Source: https://habr.com/ru/post/1333560/


All Articles