필터 지우기
필터 지우기

Generating Non Linear Equation

조회 수: 1 (최근 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 CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by