Curve fitting for power equation
2 views (last 30 days)
Show older comments
how to fit curve for an equation y=a*(x1)^b * (x2)^c; where a b and c are constants to find and we do know sets f y x1 and x2?
0 Comments
Answers (2)
David Sanchez
on 4 Jun 2014
Use the curve fitting tool
cftool % this will open the curve fitting tool interface
From the user interface, select you x, y, z, data and insert your Custom Equation (the default method is Interpolant, change it in the selection list) The rest is almost straight forward.
0 Comments
Star Strider
on 4 Jun 2014
To fit your equation using fminsearch, this works:
% —————————— Define Function ——————————
PwrEqn = @(b,x) b(1) .* x(:,1).^b(2) .* x(:,2).^b(3);
% —————————— Create Data ——————————
b = [3 5 7]; % Parameters
x = rand(20,2); % Matrix of ‘x’ values
y = PwrEqn(b,x) + rand(20,1)*0.001; % Create ‘y’ using ‘PwrEqn’ and add noise
% —————————— Fit Data and Estimate Parameters ——————————
OLS = @(b) sum((y - PwrEqn(b,x)).^2);
b = fminsearch(OLS, [1 1 1]);
fprintf(1,'Estimated parameters:\n\ta = %.4f\n\tb = %.4f\n\tc = %.4f\n\n', b)
NOTE: Your x data have to be in one (Nx2) matrix (as [x1 x2]), and y as a (Nx1) vector.
0 Comments
See Also
Categories
Find more on Interpolation 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!