Hi fellows,
I have written a code to solve a expotinal function, matlab returns an answer which seems like contain imaginary part. But I tried to plot the function and I think it indicates the function should has a real solution between 5 and 6. Could you help me find out what is the problem here? Really appreciated! The code is below (yes the loop seems unnecessary, because I just show a example so there is not need to let it do the whole loop).
%this is the maxmin when c2=0
sub=[0.3,0.3,0.3,0.08]; d1=[0.200000000000000,-0.400000000000000,0.600000000000000]rn=size(d1,1)lb1=sub(1);lb2=sub(2);lb3=sub(3);r=sub(4);for i=1:1 if (d1(i,1)==min(d1(i,:))) p1=1-lb2-lb3; p2=lb2; p3=lb3; elseif (d1(i,2)==min(d1(i,:))) p1=lb1; p2=1-lb1-lb3; p3=lb3; elseif (d1(i,2)==min(d1(i,:))) p1=lb1; p2=lb2; p3=1-lb1-lb2; end syms x; f=simplify(p1*d1(i,1)*exp(-r*x*d1(i,1))+p2*d1(i,2)*exp(-r*x*d1(i,2))+p3*d1(i,3)*exp(-r*x*d1(i,3))) y=solve(f,x) %x=-100:1:100;
%solve(0.06*exp(-0.016*x)-0.16*exp(0.032*x)+0.18*exp(-0.048*x),x)
%y=0.06*exp(-0.016*x)-0.16*exp(0.032*x)+0.18*exp(-0.048*x);
%plot(x,y)
end
Best Answer