Generating Non Linear Equation

8 ビュー (過去 30 日間)
ElevenFourth
ElevenFourth 2013 年 6 月 4 日
Hi all !
I am going to determine the value of a and b of the equation as follows :
y = 1 - ax - bx^2
where, a + b = 1
I also have a set of data to be fitted by the above equation. How can I do this with matlab?
Your guidance and help would be highly appreciated.

回答 (2 件)

the cyclist
the cyclist 2013 年 6 月 4 日
If you have the Statistics Toolbox, you can do this with nlinfit().
% Generate some pretend data to be fit
x=(0:1:10)'; % Explanatory variable
y = 1 - 0.3*x - 0.7*x.^2; % Response variable (if response were perfect)
y = y + 2*randn((size(x)));% Add some noise to response variable
% Define function that will be used to fit data
% (F is a vector of fitting parameters)
f = @(F,x) 1 - F.*x - (1-F).*x.^2;
F_fitted = nlinfit(x,y,f,[1]);
% Display fitted coefficients
disp(['F = ',num2str(F_fitted)])
% Plot the data and fit
figure
plot(x,y,'*',x,f(F_fitted,x),'g');
legend('data','fit')

Roger Stafford
Roger Stafford 2013 年 6 月 4 日
編集済み: Roger Stafford 2013 年 6 月 4 日
It depends on what you want to minimize in your "fitting". To get the least squares difference between y and the above expression, do this:
a = sum((1-y-x.^2).*(x-x.^2))/sum((x-x.*2).^2);
where x and y are vectors of the given data.
You can derive this by setting the partial derivative with respect to 'a' equal to zero and solving for 'a' for the expression
sum((y-1+a*x+b*x^2)^2)
where b is set to 1-a.

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by