function [REALrts, ALLrts] = cardanos(p,q) % CARDANOS(p,q) root finding algorithm for depressed cubic polynomial with real valued p and q % reduced form of CardanRoots for surface renewal vectors p and q to determine ramp Amplitudes % polynomial should be of form A^3 + p*A + q = 0 with p and q real valued (no complex values) % RETURNS only positive real valued solutions, with complex and negative solutions replaced with NaN % refs: Wiki % SEE ALSO: cardanroots.m % c3*x^3+c2*x^2+c1*x+c0=0 attempts at full form %{ % % Source Code % &prev cardanos(b,c,d) % bs = b.^2; % p = c-bs./3; % q = ((-2/27)*bs+(1/3)*c).*b - d; % Q = p./3; % R = q./2; % D = Q.^3 + R.^2; % k = find(D>=0); % S = zeros(length(D),1); % T = zeros(length(D),1); % S(k) = nthroot(R(k)+sqrt(D(k)),3); % T(k) = nthroot(R(k)-sqrt(D(k)),3); % % root = zeros(length(D),1); % root(k,1) = -b./3+S(k)+T(k); % root(k,2) = -b./3+(1/2).*(S(k)+T(k))+(1/2).*1i.*sqrt(3).*(S(k)-T(k)); % root(k,3) = -b./3+(1/2).*(S(k)+T(k))-(1/2).*1i.*sqrt(3).*(S(k)-T(k)); % % k=find(D<0); % phi = zeros(length(D),3); % phi(k) = acos(R(k)./sqrt(-Q(k).^3)); % root(k,1) = 2.*sqrt(-Q(k)).*cos(phi(k)./3)-b(k)./3; % root(k,2) = 2.*sqrt(-Q(k)).*cos((phi(k)+2*pi)./3)-b(k)./3; % root(k,3) = 2.*sqrt(-Q(k)).*cos((phi(k)+4*pi)./3)-b(k)./3; %} D = q.^2 + (4/27)*p.^3; % the discriminant %deltanull = abs(delta)