Complex values computed by fit.m function (Curve fitting Tool)
古いコメントを表示
Hi,
I am trying to use the fit.m function, but matlab throws the "complexValueComputed" exception, even though my x variable could not created complex values.
My x variable is: x = 1 - T./Tcrit and T is an array with max(Tsat) < Tcrit.
My y variable is an irrational function: y = a1 + a2 .*x.^(1/3) + a3 .* x.^(2/3)+ a4 .* x.^(3/3)+...
So there is just a possibilty to create complex values for Tsat > Tcrit, but this is not possible.
I even try to solve this problem by using the abs() function for my x variable, but nothing changed.
The error message is: "Complex value computed by model function, fitting cannot continue.Try using or tightening upper and lower bounds on coefficients."
and appears in fit.m in line 116 or for the iFit.m function in line 348.
Any help for resolving this problem would be greatly appreciated!
6 件のコメント
Torsten
2019 年 6 月 26 日
Your y variable becomes complex-valued if any of the a_i becomes negative.
Matti Rademacher
2019 年 6 月 26 日
編集済み: Matti Rademacher
2019 年 6 月 26 日
Matti Rademacher
2019 年 6 月 26 日
編集済み: Stephen23
2019 年 6 月 26 日
You should create function handles, rather than eval-ing some strings.
Matti Rademacher
2019 年 6 月 26 日
回答 (1 件)
Since your fitting problem is linear in the coefficients a1,a2,a3,..., this is all you need to get the best fit parameters:
A = [ones(1368,1), Tsat.^(1/3), Tsat.^(2/3), Tsat.^(3/3), Tsat.^(4/3)];
b = psat;
sol = A\b;
a1 = sol(1)
a2 = sol(2)
a3 = sol(3)
a4 = sol(4)
a5 = sol(5)
Best wishes
Torsten.
7 件のコメント
Matti Rademacher
2019 年 6 月 26 日
編集済み: Matti Rademacher
2019 年 6 月 26 日
You say that xdata and ydata are real-valued and that your fitting function can't produce complex results. If this is the case, the fitting tool will never produce complex fitting parameters.
Since you don't provide executable code and since I don't have a licence for the curve-fitting toolbox, I can't test what's wrong with your settings.
The easiest way is to write a function with the fitting expression, call this function with the xdata vector and the initial value vector for [a1 a2 ...] and see what it returns.
Matti Rademacher
2019 年 6 月 26 日
Torsten
2019 年 6 月 26 日
Try this line
ft = fittype(@(a1,a2,a3,a4,a5,x) a1+a2*x.^(1/3)+a3*x.^(2/3)+a4*x.^(3/3)+a5*x.^(4/3),'independent',{'x'},'dependent',{'y'});
instead of yours.
By the way:
x.*^(2/3), x.*^(3/3) and x.*^(4/3) doesn't make sense.
Matti Rademacher
2019 年 6 月 26 日
Torsten
2019 年 6 月 26 日
So mag(1,1) is equal to 4 in your code ?
Matti Rademacher
2019 年 6 月 26 日
カテゴリ
ヘルプ センター および 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!