# Nonlinear Optimization with conditional statement

I find Maximize doesn't work well under conditional statement. Here is an example.

A car is driving up a slope. I want to find out the largest slope angle the car can drive upwards. I choose the slope angle θ and engine torque τ as decision variables. The friction force can be described by Coulomb friction model, which is a conditional statement

The complete formulation is

Therefore, the Nonlinear Optimization can be solved by

  Maximize[{θ, 0 < θ < Pi/2 && 0 < τ < 2 &&
If[τ/r < μs*G*Cos[θ], τ/r, μd G Cos[θ]] > G Sin[θ]}, {θ, τ}]


given the parameters: G = 70; r = 0.025; μs = 0.5; μd = 0.4;

Mathematica gives θ=0.380506,,which is ArcTan[μd], whereas the expected result should be θ=0.46364,which is ArcTan[μs].

Try If[c, x > z, y > z] instead of If[c, x, y] > z:

G = 70; r = 0.025; μs = 0.5; μd = 0.4;
Maximize[{θ, 0 < θ < Pi/2 && 0 < τ < 2 &&
If[τ/r < μs*G*Cos[θ], τ/r > G Sin[θ], μd G Cos[θ] > G Sin[θ]]}, {θ, τ}]

{0.463648, {θ -> 0.463648, τ -> 0.782624}}

ArcTan[μs]

0.463648

• :@ybeltukov,aha! Thanks. There is a trick. – novice Jan 17 '14 at 2:38

Just a long comment. A bit annoying :

constr[x_, θ_] =
Piecewise[{{x - G Sin[θ], x < μs*G*Cos[θ]},
{μd G Cos[θ] - G Sin[θ], x >= μs*G*Cos[θ]}
}] ;

sol = NMaximize[Join[{θ, 0 < θ < Pi/2, 0 < τ < 2}, {constr[τ/r, θ] > 0}], {θ, τ}]
(* {0.380506, {θ -> 0.380506, τ -> 1.08698}} *)


but

constr[τ/r, θ] /. sol[[2]]
(* -8.0802*10^-6 *)

• It seems the piecewise method has the same answer as the if conditional statement. – novice Oct 21 '13 at 8:02
• Yes, you're right. I only wanted to stress that the constraints is not met, even though by a small number. – b.gates.you.know.what Oct 21 '13 at 8:16
• Is it because the friction function is not continuous? And, is there another way to impose the constraint? – novice Oct 22 '13 at 2:13