Fit a square root function to data

I would like to fit a function of form y=K*x^.5+c, where Matlab finds the best fit values of K&c. What's the best way to do this? Thanks!

回答 (1 件)

Star Strider
Star Strider 2014 年 9 月 15 日
編集済み: Star Strider 2014 年 9 月 15 日

2 投票

Your function is actually linear, so you can use any linear regression function such as the Statistics Toolbox regress function, since it supplies several statistics on the fit.
Otherwise, use the mldivide function or ‘\’ operator. Assuming x and y are row vectors in your original data:
x = linspace(0, 10, 15); % Create Data
y = 3.*sqrt(x)+5 + 0.1*randn(size(x)); % Create Data
p = [sqrt(x)' ones(size(y'))]\y'; % Estimate Parameters
The vector of estimated parameters correspond to p(1)=K and p(2)=c.
If x and y are column vectors, eliminate the transpose (') operators in the ‘p’ calcualation.
You can also use polyfit and its friends, remembering to use sqrt(x) instead of x in the argument list:
yp = polyfit(sqrt(x), y, 1);

カテゴリ

ヘルプ センター および File ExchangeLinear and Nonlinear Regression についてさらに検索

質問済み:

2014 年 9 月 15 日

編集済み:

2014 年 9 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by