MATLAB: Solve return imaginary answer for a problem should have a real solution

solve

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

It appears you are not being shown the complete solution. The general solution is of the form
(125/2)*ln(RootOf(-3*z^2+8*z^5-9, z))
Here RootOf(f(z),z) stands for the set of values of z such that f(z) becomes 0. Which is to say, the roots of a quintic. There is no general analytic solution for quintics.
The z1 that you are being shown in the solution is MuPAD's way of making the formula shorter, along the lines of saying,
"(125/2)*ln(z1) WHERE z1 = RootOf(-3*z^2+8*z^5-9, z)"
except that in R2010a, the interface between MuPAD and MATLAB does not know to show you the "WHERE z1 =" part.
What you should probably do is use
syms x real
and then in theory you should get the real root of the solution.