フィルターのクリア

How to get polynomial of form ax^2+c

5 ビュー (過去 30 日間)
David Ishak
David Ishak 2015 年 10 月 29 日
回答済み: Matt J 2015 年 10 月 29 日
I am using MATLAB to fit a curve to data. I have a physics formula of the form y=ax^2+c and I am trying to determine the value of the constant a and c using the data. When I fit a second degree polynomial to the data (using polyfit), MATLAB gives me the constants a b and c of the polynomial in the form of ax^2 + bx + c. Of course, that doesn't help me find a and c for my formula. I need a polynomial of the form ax^2 + 0x + c that fits the data

回答 (3 件)

Matt J
Matt J 2015 年 10 月 29 日
p=polyfit(x.^2,y,1);
a=p(1);
c=p(2);

Walter Roberson
Walter Roberson 2015 年 10 月 29 日
Suppose you have an x vector and a y vector. Then
X = x(:);
Y = y(:);
coeffs = [X.^2, ones(size(X))] \ Y;
a = coeffs(1);
c = coeffs(2);

Star Strider
Star Strider 2015 年 10 月 29 日
編集済み: Star Strider 2015 年 10 月 29 日
You have a linear equation, so you can use the mldivide function and an appropriately constructed design matrix to estimate the parameters:
x = 0:9; % Create Data
y = 2 + 5*x.^2 + 0.1*randn(size(x)); % Create Data
B = [ones(size(x(:))) x(:).^2]\y' % Estimate Parameters
B =
2.0176
4.9998
The ‘B’ assignment is the parameter vectors, with c=B(1) and a=B(2).

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by