Generating Non Linear Equation
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
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')
0 件のコメント
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interpolation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!