How to remove complex numbers from feval

When I run this code to evaluate the equations (using simple feval functions) I get complex answers resulting in the plot shown. How does one handle this in the code to get a single line fit that I need and get rid of the complex solutions?
The 2 column table being read in is ejust xperimental data from uni thats been cleaned and Ive tried using statements with real(x) etc that doesnt work.
Many thanks for the help
GSI = 100;
D = 0;
Sig3 = TeoFQI.Sig3;
Sig1 = TeoFQI.Sig1;
HoekBrown = @(b,Sig3)(Sig3+b(1)*((b(2)*exp((GSI-100)/(28-14*D))*(Sig3/b(1))+ exp((GSI-100)/(9-3*D)))).^(0.5+1/6*(exp(-GSI/15)-exp(-20/3))));
opts = statset('nlinfit');
beta0 = [100;7];
beta = nlinfit(Sig3,Sig1,HoekBrown,beta0,opts)
S3min = min(Sig3)
S3max = max(Sig3)
figure()
plot(Sig3,Sig1,'o')
hold on
S3 = linspace(-6,S3max+4,100)
HB=@(Sig3x) Sig3x+beta(1)*((beta(2)*exp((GSI-100)./(28-14*D)).*(Sig3x/beta(1))+ exp((GSI-100)/(9-3*D)))).^(0.5+1/6.*(exp(-GSI/15)-exp(-20./3)));
y = feval(HB,S3)
plot(S3,real(y))
hold off
mb = beta(2).*exp((GSI-100)./(28-14*D));
s = exp((GSI-100)/(9-3*D));
a= 0.5+1/6*(exp(-GSI/15)-exp(-20/3));
SigciHold = beta(1)
SigN = @(Sig1x,Sig3x) ((Sig1x+Sig3x)/2 - (Sig1x-Sig3x)/2*(((1+a.*mb.*(mb*Sig3x./SigciHold+s).^(a-1))-1)/((1+a.*mb.*(mb*Sig3x./SigciHold+s).^(a-1))+1)));
SigN_Evaluated = feval(SigN,y,S3)
Tau = @(Sig1x,Sig3x) ((Sig1x-Sig3x).*(sqrt(1+a.*mb.*(mb.*Sig3./SigciHold+s).^(a-1)))./((1+a.*mb.*(mb.*Sig3./SigciHold+s).^(a-1))+1));
Tau_Evaluated = feval(Tau,y,S3)
figure()
plot(SigN_Evaluated,Tau_Evaluated,'o')

댓글 수: 4

Walter Roberson
Walter Roberson 2019년 1월 19일
It sounds as if you need a technique that supports bounds.
I wonder if https://www.mathworks.com/help/matlab/ref/lsqnonneg.html could be used? Or something from the Curvefitting Toolbox, as that supports lower and upper bounds.
Ken Mercer
Ken Mercer 2019년 1월 19일
Ive tried changing the bounds but no difference still results in a complex solution
Walter Roberson
Walter Roberson 2019년 1월 20일
nlinfit() does not appear to me to support bounds parameters.
It would help us to test if you supplied the data.
Ken Mercer
Ken Mercer 2019년 1월 20일
Walter many thanks you were corrent it is a bounds issue. Now resolved.

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

답변 (0개)

카테고리

제품

릴리스

R2018b

질문:

2019년 1월 19일

댓글:

2019년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by