I have the following piece of code which takes 100 times longer than simple double precision calculation on my laptop. Is this expected?
s = 0.00001;
delta = 0.9;
e = linspace(0,2,1015);
gamma = 1e-05;
for i = 1:100
m = mp((delta/s)^2 - 1); b = mp(-2*(1i*e-gamma)./s);
p1 = m - b.^2/8; p2 = - b*(m + 2)/2;
h1 = (b.^2/4 + m).^2;
h2 = b.^6/32+(3*b.^4*m)/8+(3*b.^2*m^2)/2+27*b.^2*m+27*b.^2+2*m^3;
S = (1/2*(h2+sqrt(h2.^2-4*h1.^3))).^(1/3);
S = 1/2*sqrt(-2/3*p1+1/3*(S+h1./S));
sol = -b./4+S+1/2*sqrt(-4*S.^2-2*p1-p2./S);
sol = double(sol);
P.S. this is the application of Cardano formula to find the roots of a quartic polynomial when coefficients vary.
I have bolded the parts that need to be changed if run using MATLAB double precision arithmetic.
Customer support service by UserEcho