Mikael Hakman
Mikael Hakman

Reputation: 61

Mathematica Solve function gives incorrect solution, why?

Please look into attached file. I’m using Mathematica Solve function to solve some simple equations from physics. One of the equations is an If function which defines function value when a condition is met. Solve finds almost correct solution which itself is a ConditionalExpression. For independent variable θ = 90° the answer given by Solve is in error. It seems that Solve forgets the case when Cos equals 0. Why? Thanks.

Regards/Mikael Friction Model

Upvotes: 2

Views: 661

Answers (2)

Mikael Hakman
Mikael Hakman

Reputation: 61

Many thanks Chris.

Yes, giving it real numbers yields correct answers. This is because Cos[90.0°] is 6.123233995736766E-17 whereas Cos[90°] is 0. The solution is the same but we are fooling it with finite machine precision.

If I ask me, I would say that this is a bug in equation solver in Mathematica. The solution produced by Solve[] should test for Cos[] >= 0. Now it tests for Cos[] > 0 which is not true for Cos[90°].

Upvotes: 1

Chris Degnen
Chris Degnen

Reputation: 8680

Specifying theta as a real solves the problem.

w = 1500;
mus = 0.4;
fv = f Cos[theta Degree];
fh = f Sin[theta Degree];
fn = fv + w;
ff = If[mus fn >= 0, mus fn, 0];
frul = Quiet@Solve[fh == ff, f, Reals];
f /. frul /. theta -> 90.

{600.}

f /. frul /. theta -> 90

{Undefined}

Same again, with radians.

w = 1500;
mus = 0.4;
fv = f Cos[theta];
fh = f Sin[theta];
fn = fv + w;
ff = If[mus fn >= 0, mus fn, 0];
frul = Quiet@Solve[fh == ff, f, Reals];
f /. frul /. theta -> N[Pi/2]

{600.}

f /. frul /. theta -> Pi/2

{Undefined}

Upvotes: 2

Related Questions