3

I have a system of two linear differential equations, where the initial conditions depend on a parameter. I want to find the value for this parameter $\lambda$ such that the solution evaluated in one particular point $x_0$ takes some value (in particular, the quotient between the components of the solution vector).

In order to achieve this, I have build a function that admits as input a value for this parameter $\lambda$, uses it to solve the system and then returns the value at the desired point $x_0$. I called this, solver[lambda].

So I was wondering if I could use FindRoot in the followoing way

FindRoot[solver[lambda]-value,{lambda,lambdaInit}]

where value is the value I want and lambdaInit is an initial value for $\lambda$ that I know is close to the desired one.

Does this make sense? Maybe depending on the method applied by FindRoot?

dpravos
  • 655
  • 4
  • 12
  • 5
    You should consider looking at ParametricNDSolve, which returns a family of solutions to the differential equations parameterized by some quantity, which in your case would be $\lambda$. That way, you get a function back that can be used inside FindRoot. – march Sep 20 '16 at 17:12
  • Do what march said, but I wrote a more generally applicable answer anyway. – Szabolcs Sep 20 '16 at 17:45

1 Answers1

5

Yes, you can.

Define solver so that it doesn't evaluate for symbolic arguments:

solver[lambda_?NumericQ] := ...

Then just use FindRoot normally. It will select the method automatically.

It is also true that not all methods can be used. Newton's method requires the (symbolic) derivative but e.g. the secant method doesn't.

You'll find detailed documentation in the second section here:

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263