# Getting FindRoot::nlnum when trying to find root of an Interpolating function [closed]

I want to solve a system of differential equations and find a point where the solutions cross. So four steps: 1. Solve the system of differential equations:

soln = NDSolve[Deqns ⋃ InitialConditions,
{Cwee, Cvee, Cuee, Swee, svee, Swee, Svee, suee},
{gamma, 0, maxgamma},
WorkingPrecision -> 40,
MaxSteps ->∞]

1. Test the domain of the solution

First[Swee["Domain"] /. First[soln]] == First[Svee["Domain"] /. First[soln]]
TheDomain = Prepend[First[Swee["Domain"] /. First[soln]], gamma]

2. Plot Swee[gamma] - Svee[gamma]

Plot[(Swee /. soln[[1]])[gamma] - (Svee /. soln[[1]])[gamma], Evaluate[TheDomain]]


That produces a nice smooth curve that crosses zero in the middle of the domain.

1. Find the root

FindRoot[(Swee /. soln[[1]])[gamma] - (Svee /. soln[[1]])[gamma],
Evaluate[TheDomain]]


That gives me the FindRoot:nlnum error

FindRoot::nlnum: "The function value {<<1>>} is not a list of numbers with
dimensions {1} at {gamma} = {5.287145818278696*^6}"

FindRoot[(Swee /. soln[[1]])[gamma] - (Svee /. soln[[1]])[gamma],
{gamma,
5.287145818278696407111922220268007520747*10^6,
5.287267309479576564179954666398942570797*10^6}]


I tried many different ways of writing the function Swee[gamma] - Svee[gamma] using Evaluate, N, ...all produce the same result. I can implement a simple line search on the function (Swee /. soln[[1]])[gamma] - (Svee /. soln[[1]])[gamma], but why reinvent the wheel?

• Hi ! You can include a minimal working example -- say an equation and its init/boundary values, etc – Sektor Mar 15 '16 at 15:34
• I worked it out. Thanks! The problem occurs at the boundaries of the Domain. If I restrict the search to the interior of the Domain, it works fine, – John V Mar 15 '16 at 15:36
• Look up WhenEvent[]`. – J. M.'s technical difficulties Mar 15 '16 at 15:38