简体   繁体   中英

Matlab Curve Fitting without Toolbox

I am trying to find a fitting curve as described below. MATLAB's polyfit does not work in my case.
Known parameters: x and y , and the fitting curve y_fit = a * (x_fit) .^ n
(here, n may not be an integer).
I need to find a and n .

Take the logarithm of both sides and use polyfit or just a plain x = A\\b approach.

y_fit = a*(x_fit).^n

log(y_fit) = log(a) + n*log(x_fit)

If x_fit and y_fit are column vectors of data:

A = [ones(length(x_fit), 1), log(x_fit)];
b = log(y_fit);
x = A\b;
n = x(2)
a = exp(x(1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM