Curve fitting for power equation
古いコメントを表示
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?
回答 (2 件)
David Sanchez
2014 年 6 月 4 日
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.
Star Strider
2014 年 6 月 4 日
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.
カテゴリ
ヘルプ センター および File Exchange で Least Squares についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!