fit function breaches the lower option limits

I was trying to do fit with a script generated from cftool. It puts lower limit of 0 on all coefficients and the result returned is still negative. I would like to share the dataset but I am new to this forum and I don't find any option of sharing file. Please help me.

 채택된 답변

Amol
Amol 2011년 2월 3일

0 개 추천

0 votes Edit Delete Amol answered less than a minute ago
ok here is the script
function [cf_,gof]=myfit(tau,avar,weight)
%MYFIT Create plot of datasets and fits
% MYFIT(TAU,AVAR,WEIGHT)
% Creates a plot, similar to the plot in the main curve fitting
% window, using the data that you provide as input. You can
% apply this function to the same data you used with cftool
% or with different data. You may want to edit the function to
% customize the code and this help message.
%
% Number of datasets: 1
% Number of fits: 1
% Data from dataset "avar vs. tau with weight":
% X = tau:
% Y = avar:
% Weights = weight:
%
% This function was automatically generated on 04-Nov-2009 17:20:51
% --- Create fit "fit 1"
fo_ = fitoptions('method','LinearLeastSquares','Lower',[0 0 0 0 0]);
ok_ = isfinite(tau) & isfinite(avar) & isfinite(weight);
set(fo_,'Weight',weight(ok_));
if ~all( ok_ )
warning( 'GenerateMFile:IgnoringNansAndInfs', ...
'Ignoring NaNs and Infs in data' );
end
ft_ = fittype({'1/(x^2)', '1/x', 'x', 'x^2', '1'},...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a', 'b', 'd', 'e', 'c'});
% Fit this model using new data
[cf_,gof] = fit(tau(ok_),avar(ok_),ft_,fo_);
% Or use coefficients from the original fit:
%if 0
% cv_ = { 2.8012463154944958529e-09, 4.1224210467149593554e-06, -6.2806159338057854499e-10, 1.1525415994665557154e-11, 5.4419882197796621562e-07};
% cf_ = cfit(ft_,cv_{:});
end
and yes I am sorry for a late response. I seems that i need to turn on some option to get email notification from the forum

댓글 수: 7

By the way, at present the forum does not generate email notifications. There is some support, though, for RSS feeds.
What magnitude of data are you passing in to be fitted? Looking at those coefficients in the comment, it does not appear to me that your fit is numerically stable.
Amol
Amol 2011년 2월 4일
the x data spans from 10e-2 to 10e6
y data sans from 10-3 to 10
(1E6)^2 = 1E12
1/(1E6)^2 = 1E-12
You are thus attempting to form systems with a range of 1E24, which is more than can be worked with in binary floating point numbers -- the maximum range is about 1E16.
Therefore you cannot expect to be able to fit your data without calculations that might take some coefficients negative due to round-off error.
Amol
Amol 2011년 2월 4일
is it true unconditionally?
It is unconditionally true that IEEE Double Precision Binary Floating Point numbers have 53 bits of precision, which is a dynamic range of about 1E-16.
If you need greater precision, then you need to either use the Symbolic Toolbox, or the Fixed Point Toolbox, or the Matlab File Exchange contribution for Variable Precision calculations, vpi . Note though that the functions you are wanting to use are probably not defined with any of these kinds of numeric representation.
Amol
Amol 2011년 2월 7일
thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

질문:

2011년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by