1
$\begingroup$

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?

$\endgroup$

closed as off-topic by MarcoB, m_goldberg, user9660, Öskå, Michael E2 Jul 1 '16 at 0:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, m_goldberg, Community, Öskå, Michael E2
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Hi ! You can include a minimal working example -- say an equation and its init/boundary values, etc $\endgroup$ – Sektor Mar 15 '16 at 15:34
  • 2
    $\begingroup$ 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, $\endgroup$ – John V Mar 15 '16 at 15:36
  • 1
    $\begingroup$ Look up WhenEvent[]. $\endgroup$ – J. M. will be back soon Mar 15 '16 at 15:38