Multivariate Nonlinear Least Squares

20 Ansichten (letzte 30 Tage)
jlt199
jlt199 am 27 Jul. 2016
Kommentiert: Star Strider am 3 Jun. 2019
Morning everyone,
I've tried talking to MathWorks and playing with the tools in the curve fitting toolbox, but I can't seem to find a solution to my problem.
I have a model Y(P,W,L) = P^a * W^b *L^c + d where a, b, c and d are unknown coefficients I need to find. I have vectors for Y, P, W and L.
Please can you help me find a solution to this problem. I was told that the curve fitting toolbox was the way to go, but so far I haven't had any success setting up the model using fittype.
I would really appreciate a quick response to this problem as I need to have found a solution and reported my findings by this Friday.
Many thanks

Akzeptierte Antwort

Star Strider
Star Strider am 27 Jul. 2016
I don’t have the Curve Fitting Toolbox, so I’m using fminsearch here:
P = randi(9, 10, 1); % Create Data
W = randi(9, 10, 1); % Create Data
L = randi(9, 10, 1); % Create Data
Y = randi(9, 10, 1); % Create Data
PWL = [P(:) W(:) L(:)]; % Create Single Variable
% % MAPPING: b(1) = a, b(2) =b, b(3) = c, b(4) = d
Y_fit = @(b,PWL) PWL(:,1).^b(1) + PWL(:,2).^b(2) + PWL(:,3).^b(3) + b(4);
SSECF = @(b) sum((Y(:) - Y_fit(b,PWL)).^2); % Sum-Squared-Error Cost Function
B0 = [1; 1; 1; 1]; % Initial Parameter Estimates
[B, SSE] = fminsearch(SSECF, B0); % Estimate Parameters
figure(1)
subplot(3,1,1)
plot(P, Y,'xr', P, Y_fit(B,PWL),'bp')
grid
subplot(3,1,2)
plot(W, Y,'xr', W, Y_fit(B,PWL),'bp')
grid
subplot(3,1,3)
plot(L, Y,'xr', L, Y_fit(B,PWL),'bp')
grid
I added the plots, since it usually helps me determine how good the fit is. If you want to plot your data and the regression, you will have to experiment with the plots, since they can be a bit difficult when you have three independent variables. The plotting I did here works, but it may not be the best for your data.
  6 Kommentare
LANDON THOMAS KAMPS
LANDON THOMAS KAMPS am 3 Jun. 2019
Thanks for the nice curve-fitting module.
This is working great for me too.
Much appreciated
Star Strider
Star Strider am 3 Jun. 2019
@Landon —
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by