# Numerical Methods - minimum of a function

## Problem:

The length of the longest ladder that can negotiate the corner depicted in Figure 2 can be determined by computing the value of theta that minimizes the following function:

$L(theta)=w1/sin(theta)+w2/sin(pi-alpha-theta)$

For the case where w1 = w2 = 2 m, use a numerical method to develop a plot of L versus a range of alpha 's from 45 to 135 degrees. ## Solution so far:

Until now, I could think of 2 methods for solving this problem:

The first method was to compute the derivative and solve the equation L'(theta)=0 and from here find theta for which the function has a minimum value. Here is the code:

L[th_] := 2/Sin[th] + 2/Sin[135 Degree - th]
NSolve[D[2/Sin[th] + 2/Sin[135 - th], th] == 0, th]
N[Minimize[D[L[th], th], {th > 0}, th]]


The output of NSolve gives me the following error NSolve::ifun: Inverse functions are being used by NSolve, so some solutions may not be found; use Reduce for complete solution information and this results

{{th -> -1.61504}, {th -> -0.0442421 - 0.0442132 I},
{th -> -0.0442421 + 0.0442132 I}, {th -> 1.52655},
{th -> 3.09735 - 0.0442132 I}, {th -> 3.09735 + 0.0442132 I}}


which are a lot of values and I don't know which one is the right one. For the Minimize function I get this error and nothing gets computed NMinimize::nnum: The function value (L^\[Prime])[0.0914636] is not a number at {th} = {0.0914636}. >>

The second approach was to use a root-location technique. I chose the Newton-Raphson, but the results obtained were in a strange form. This is the code:

th1 = 1

thl = 10

thu = 100

thr = thu - (L (thu)*(thl - thu))/(L (thl) - L (thu))

NewRa = {1}

h = D[L[th], th]

For[i = 2, i <= 4, i++, a = NewRa[[i - 1]]; b = h /. x -> a;
AppendTo[NewRa, a - L[a]/b]]

NewRa

{1, 1 - (2 Csc + 2 Csc[1 + 45 \[Degree]])/(-2 Cot[th] Csc[th] -
2 Cot[45 \[Degree] + th] Csc[45 \[Degree] + th]),
1 - (2 Csc + 2 Csc[1 + 45 \[Degree]])/(-2 Cot[th] Csc[th] -
2 Cot[45 \[Degree] + th] Csc[45 \[Degree] + th])


Am I approaching the problem in the right way? If yes, how can I solve the error from Mathematica?

## 1 Answer

 Plot[ First@
FindMinimum[{  2/Sin[th] + 2/Sin[ Pi - (alpha Degree) - th] ,
0 < th < Pi - alpha Degree} , th] , {alpha, 45, 135},
PlotRange -> {0, Automatic}] Your NSolve approach works as well, the key is to limit the range:

NSolve[{ D[2/Sin[th] + 2/Sin[Pi - 100  Degree - th], th] == 0,
Pi - 100 Degree > th > 0}, th]

• It worked. Thank you – Contourette. Mar 21 '14 at 21:16