3 independent variable regression.

I'm trying to fit a function with 3 independent variables and 1 dependent. I have all of the data and I've tried a few methods but nothing works.
I want a function set up so that the result would be F where F = f(x,y,z). Developing a model from a matrix of [ x, y, z, F] values. Any suggestions?
To clarify, I don't need to plot it (yet if ever).

3 Comments

The code I used that ended up working was as follows:
%Fit Plot
fitobject = fit([X1,Y1],Z1,'poly11')
%Degree Polynomial ' poly11', poly'22' etc. each Number represents the degree of each variable
figure (3)
plot(fitobject,[X1,Y1],Z1)
hold on
grid on
title('title')
set(gca, 'ZLim',[0 6])
shading interp
hold off
Hey,
i have the same problem too.I'm trying to fit a function with 3 independent variables and 1 dependent. I have all of the data. i mean the values of all 3 independent variables and 1 dependent are known
but i dont undrestand the solution you have written.
i mean where is F?
i hope you check it. i really appreciate it
% Q, H and Theta are the three independent variables
Q = [0.5;0.6;0.8;0.9;0.99;1;1;1;1.2;1.2;1.2;1.2;1.5;1.5;1.6;1.8;2;2.3;2.5;2.5;2.8;3.2;3.5;4.5;5.5;6;6;7.1;8];
H = [5;5.3;1.35;2.1;1.05;3.16;3;5;3.57;1.75;3.2;1;3;3.17;1.1;3.45;1.8;2.55;2.55;1.8;2.1;3.6;4.05;1.5;5;5.8;2.97;1.7;1.73];
Theta = [28.5;31.2;25;21.6;20.3;25.2;30;28.9;21.8;22.8;28.7;18.8;20.2;22;20.6;21.5;21.9;22.8;20.4;21.1;19.2;26.4;24.5;17.2;22.9;22.3;25.8;22;19.2];
% Eff is the dependent variable
Eff = [64.8;60.9;70.8;75;71.6;67.7;71.4;67.3;69;67.5;71.5;68;74.8;70.7;73;75.5;73.6;76.5;73.2;70.2;74.5;70.8;70.5;72.6;71.2;73.2;74.4;70.9;72.9];
i want a function for Eff(Q,H,Theta)

Sign in to comment.

Answers (1)

Ameer Hamza
Ameer Hamza on 10 Sep 2020
There are several ways to solve such problems in MATLAB. If you have the curve fitting toolbox, then you can use fit(): https://www.mathworks.com/help/releases/R2020a/curvefit/fit.html
Alternatively, you can also use functions from optimization toolbox

3 Comments

I tried those, and the best I could fit was for a surface. 2 independent variables for equations like F = f(x,y).
See this example using lsqcurvefit() for 3 independent variables
x = rand(10, 1);
y = rand(10, 1);
z = rand(10, 1);
F = 2*x+5*log(x+z)-3*sin(y); % example
fun = @(p,X) p(1)*X(:,1) + p(2)*log(X(:,1)+X(:,3)) - p(3)*sin(X(:,2));
X = [x y z];
sol = lsqcurvefit(fun, rand(1,3), X, F);
Yeah, but my F values are an equally sized array and not a function, so the fitting doesn't work.

Sign in to comment.

Categories

Asked:

on 10 Sep 2020

Commented:

on 11 Jul 2021

Community Treasure Hunt

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

Start Hunting!