Multivariate Nonlinear Least Squares
31 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 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 Comments
LANDON THOMAS KAMPS
on 3 Jun 2019
Thanks for the nice curve-fitting module.
This is working great for me too.
Much appreciated
More Answers (0)
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!