How do I define an output vector as real and positive

6 ビュー (過去 30 日間)
Christos
Christos 2014 年 9 月 21 日
編集済み: Roger Wohlwend 2014 年 9 月 22 日
Hi all
I am currently running this script to fit a complex function on my data using lsqcurvefit.
clear all;
hold off E1=importdata('E1.mat'); %E1 and DR1 are the names of my arrays
DR=importdata('DR1.mat');
hold on plot(E1,DR)
%x(1)=C
%x(2)=f
%x(3)=Eg
%x(4)=G
x0= [1 0 1 0.02 ];
F=@(x,E1)x(1)*exp(1i*x(2))./((E1-x(3)-1i*x(4))^2);
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,E1,DR);
plot(E1,F(x,E1),'--r')
hold off
It is working perfectly except for the part where all the fitted parameters are returned as complex numbers when they should be real and positive. Is there some way to fix this?
Thanks in advance
  1 件のコメント
Star Strider
Star Strider 2014 年 9 月 21 日
I don’t know what you are doing, but (from the Euler identities), exp(1i*x(2)) will be evaluated essentially as cos(x(2)) + i*sin(x(2)), and you are also multiplying x(4)^2 by 1i. If you do not want complex parameters, you will likely have to re-write your model. I would go to the literature to see what others have done in similar situations.

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

回答 (1 件)

Roger Wohlwend
Roger Wohlwend 2014 年 9 月 22 日
編集済み: Roger Wohlwend 2014 年 9 月 22 日
The same question occured recently on Matlab answers: Link to the question.

カテゴリ

Help Center および File ExchangeLeast Squares についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by