Complex value computed by model function, fitting cannot continue. ... (2024)

34 ビュー (過去 30 日間)

古いコメントを表示

Daniel Jiao 2024 年 6 月 3 日 2:24

  • リンク

    この質問への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and

  • リンク

    この質問への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and

コメント済み: Matt J 約2時間 前

  • 200ms_SD.xlsx

Hello, I really need some help on data fitting. I would like to fit my data custom equation:a+b*exp((-(x/c))^d. I try to use upper and lower bounds on coefficients but it does not work.If anyone can tell me what to do to resolve this I would greatly appreciate it.

4 件のコメント

2 件の古いコメントを表示2 件の古いコメントを非表示

Torsten 約22時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178026

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178026

編集済み: Torsten 約22時間 前

The expression a+b*exp((-(x/c))^d cannot become complex-valued. My guess is that you use a different expression in your code.

Matt J 約21時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178066

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178066

編集済み: Matt J 約21時間 前

We do not know what you tried (no code is shown), so we cannot guess what went wrong. I will point out though that the model is over-parametrized. It is enough to use 3-parameters y=a+b*exp(-c*x). No custom equation is needed for this - it falls within the 'exp2' fitType of the fit() command.

Torsten 約21時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178086

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178086

Daniel Jiao 約2時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178846

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178846

@Torsten Thanks lot, I'll check it. This equation is given by an article, so it's a theoretical formula, but yeah, I'll check whether it's correct, thanks so much!

サインインしてコメントする。

サインインしてこの質問に回答する。

回答 (2 件)

Matt J 約21時間 前

  • リンク

    この回答への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#answer_1466586

  • リンク

    この回答への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#answer_1466586

編集済み: Matt J 約19時間 前

MATLAB Online で開く

  • 200ms_SD.xlsx

fminspleas from this FEX download,

https://www.mathworks.com/matlabcentral/fileexchange/10093-fminspleas

is helpful for these kinds of models.

[x,y]=readvars('200ms_SD.xlsx');

flist={1,@(c,x) exp(-c*x)};

[c,ab]=fminspleas(flist,+1,x,y);

a=ab(1);

b=ab(2);

f=@(x)a+b*exp(-c*x);

xf=linspace(min(x),max(x));

plot(x,y,'.c',xf,f(xf)); axis padded; legend Data Fit

Complex value computed by model function, fitting cannot continue. ... (7)

3 件のコメント

1 件の古いコメントを表示1 件の古いコメントを非表示

Matt J 約19時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178131

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178131

MATLAB Online で開く

  • 200ms_SD.xlsx

Here is the same approach as applied to y=a+b*exp(-(x/c)^d)

[x,y]=readvars('200ms_SD.xlsx');

flist={1,@(p,x) exp(-(p(1)*x).^p(2))};

[p,ab]=fminspleas(flist,[1;1],x,y,[0;0]);

a=ab(1);

b=ab(2);

c=p(1);

d=p(2);

f=@(x)a+b*exp(-(c*x).^d);

xf=linspace(min(x),max(x));

plot(x,y,'.c',xf,f(xf)); axis padded; legend Data Fit

Complex value computed by model function, fitting cannot continue. ... (9)

Daniel Jiao 約5時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178776

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178776

Thanks a lot for this answer, it really give me some ideas and confidence, as the comment you mentioned above, I just try to use fit() and fittype(), like:

ft = fittype( 'a+b*exp((-(x/c))^d)', 'independent', 'x', 'dependent', 'y' );

fitobject = fit(x,y,ft,'lower',[-1,0,0.002,0],'upper',[0,3,0.005,1]);

and I also use the curve fitting toolbox. Just some basic way, since it was first time I try to do curve fitting.

Anyway that's really helpful! Thanks so much for that, and I'll try it!

Matt J 約2時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178851

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178851

You're welcome, but when you've decided upon a solution, please Accept-click the appropriate answer.

サインインしてコメントする。

Mathieu NOE 約21時間 前

  • リンク

    この回答への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#answer_1466616

  • リンク

    この回答への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#answer_1466616

MATLAB Online で開く

  • 200ms_SD.xlsx

hello

a very basic code using only fminsearch (no toolbox required )

I preferred to smooth a bit your data (otherwise it looks more like a cloud) but it's not absolutely needed - but you end up with other parameters after the fit

hope it helps !

data = readmatrix('200ms_SD.xlsx');

x = data(:,1);

y = data(:,2);

[x,ia,ic] = unique(x);

y = y(ia);

ys = smoothdata(y,'gaussian',100);

% curve fit using fminsearch

% model a+b*exp((-(x/c))^d

f = @(a,b,c,d,x) a + b.*exp(-(x/c).^d);

obj_fun = @(params) norm(f(params(1), params(2), params(3), params(4),x)-ys);

sol = fminsearch(obj_fun, [ys(end),(max(ys)-ys(end)),1,1]);

Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 1.159572

a_sol = sol(1)

a_sol = 0.0903

b_sol = sol(2)

b_sol = 0.5209

c_sol = sol(3)

c_sol = 0.0028

d_sol = sol(4)

d_sol = 0.1143

y_fit = f(a_sol, b_sol, c_sol, d_sol, x);

R2 = my_R2_coeff(ys,y_fit); % correlation coefficient

plot(x,y, 'k.',x,ys,'r',x, y_fit,'b-')

title([' Fit / R² = ' num2str(R2) ], 'FontSize', 15)

legend('raw data','smoothed','fit');

Complex value computed by model function, fitting cannot continue. ... (13)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function R2 = my_R2_coeff(data,data_fit)

% R2 correlation coefficient computation

% The total sum of squares

sum_of_squares = sum((data-mean(data)).^2);

% The sum of squares of residuals, also called the residual sum of squares:

sum_of_squares_of_residuals = sum((data-data_fit).^2);

% definition of the coefficient of correlation (R squared) is

R2 = 1 - sum_of_squares_of_residuals/sum_of_squares;

end

1 件のコメント

-1 件の古いコメントを表示-1 件の古いコメントを非表示

Daniel Jiao 約5時間 前

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178781

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2124786-complex-value-computed-by-model-function-fitting-cannot-continue-try-using-or-tightening-upper-and#comment_3178781

Hello,thanks a lot for the answer, it's really helpful! I'll try to read and try the code you offered! My original code is much more basic, since I'm just a beginner.

Thanks again that I really got some knowledge from you!

サインインしてコメントする。

サインインしてこの質問に回答する。

参考

カテゴリ

AI, Data Science, and StatisticsCurve Fitting ToolboxGet Started with Curve Fitting Toolbox

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

タグ

  • curve fitting
  • data fitting

製品

  • MATLAB

Community Treasure Hunt

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

Start Hunting!

エラーが発生しました

ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。


Translated by Complex value computed by model function, fitting cannot continue. ... (15)

Complex value computed by model function, fitting cannot continue. ... (16)

Web サイトの選択

Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:

また、以下のリストから Web サイトを選択することもできます。

南北アメリカ

  • 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
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

アジア太平洋地域

最寄りの営業オフィスへのお問い合わせ

Complex value computed by model function, fitting cannot continue. ... (2024)
Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 5625

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.