Apple Cola
Apple Cola

Reputation: 27

Mathematica: 'Findroot' not returning expected result

I am currently doing a little project which involves using a pre-defined function I graphed the function, and I am trying to find an x-value answer using a provided y-coordinate. I'm sure there may be other ways, but I must use this particular function. Below is what I currently have:

F[L_] := (ArcTan[(L + 80)/25]/Pi + 0.6)*(0.55 - 
    0.4*Cos[(Pi/100)*(L + 10)])

FindRoot[F[L] == 0.8, {x, 55}]

I am sure that my function is correct, as I am able to retrieve a graph, which looks right for the function.

I am unsure if maybe I should try changing my '55' value?

Here is the error that I receive from the program:

FindRoot::nlnum

Upvotes: 1

Views: 619

Answers (2)

Chris Degnen
Chris Degnen

Reputation: 8655

f[x_] := (ArcTan[(x + 80)/25]/Pi + 0.6) (0.55 - 0.4 Cos[(Pi/100) (x + 10)])

Plot[{f[x], 0.8}, {x, -1000, 1000}]

enter image description here

NSolve[{f[x] == 0.8, 0 < x < 1000}, x]
{{x -> 58.2501}, {x -> 122.963}, {x -> 256.049}, {x -> 324.199}, {x -> 455.505},
 {x -> 524.599}, {x -> 655.26}, {x -> 724.797}, {x -> 855.12}, {x -> 924.915}}

Upvotes: 1

SPPearce
SPPearce

Reputation: 153

In your FindRoot you have F[L], but then you are trying to start at x=55 - you have mixed up your variables. Either put both to be L or both to be x in the FindRoot.

FindRoot[F[L] == 0.8, {L, 55}]
(* {L -> 58.2501} *)

Currently it is looking for a solution starting at L=55, there are other solutions for larger values of L:

FindRoot[F[L] == 0.8, {L, 155}]
(* {L -> 122.963} *)

Upvotes: 1

Related Questions