Post Reply 
cubic solver
07-03-2024, 11:48 PM
Post: #9
RE: cubic solver
Based from previous post lua code (depressed cubic code not needed anymore)

HP Prime Cas
Code:
#cas
quadratic(a,b,c) := 
BEGIN
LOCAL d;
b /= -2;
d := normal(sqrt(b*b-a*c));
b -= d * (-1) ^ bool(abs(b+d) >= abs(b-d));
return [b/a, (b ? c/b : b)];
END;

cubic(a,b,c,d) :=
BEGIN
a *= 3;
c := b*b-a*c;
d := 3*a*a*d - b*(b*b-3*c);
d := quadratic(1, d, c^3)[1];
d := normal(surd(d,3));
c := d ? c/d : 0;
c, d := (d+c)/-2, sqrt(-3)/2*(d-c);
return [(-c-c-b)/a, (c+d-b)/a, (c-d-b)/a];
END;
#end

XCas
Code:
quadratic(a,b,c) := { local d;
b /= -2;
print(d := normal(b*b-a*c));
d := sqrt(d);
b -= d * (-1) ^ bool(abs(b+d) >= abs(b-d));
return [b/a, (b ? c/b : b)];
}

cubic(a,b,c,d) := {
a *= 3;
c := b*b-a*c;
d := 3*a*a*d - b*(b*b-3*c);
d := quadratic(1, d, c^3)[0];
d := normal(surd(d,3));
c := d ? c/d : 0;
c, d := (d+c)/-2, sqrt(-3)/2*(d-c);
return [(-c-c-b)/a, (c+d-b)/a, (c-d-b)/a];
}
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
cubic solver - Albert Chan - 09-08-2023, 02:26 PM
RE: cubic solver - Albert Chan - 09-08-2023, 02:44 PM
RE: cubic solver - parisse - 09-08-2023, 06:56 PM
RE: cubic solver - Albert Chan - 06-29-2024, 02:46 PM
RE: cubic solver - Albert Chan - 06-29-2024, 03:29 PM
RE: cubic solver - Albert Chan - 07-02-2024, 02:34 PM
RE: cubic solver - Albert Chan - 07-02-2024, 05:12 PM
RE: cubic solver - Albert Chan - 07-03-2024, 10:17 PM
RE: cubic solver - Albert Chan - 07-03-2024 11:48 PM
Quarter Solver - Albert Chan - 07-04-2024, 08:37 PM



User(s) browsing this thread: 11 Guest(s)