显示 更早的评论
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.
采纳的回答
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.
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.
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.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
