3

i was trying to solve a problem relative to root finding in a system of differential equations; here's a simpler case.

With two distinct set of parametric differential equations, i'm able to find the root like so

funA = ParametricNDSolveValue[{y'[x] == a y[x], y[0] == 1}, 
   y, {x, -10, 10}, a];
funB = ParametricNDSolveValue[{y'[x] == - a y[x], y[0] == 1}, 
   y, {x, -10, 10}, a];

FindRoot[{funA[a][x] == 1/E, 
  funB[a][x] == E}, {{a, 0, 1}, {x, -5, 5}}]

(* {a -> 0.152329, x -> -6.49596} *)

however, if i try the same set of equations in the same function the following does not work

funC = ParametricNDSolveValue[{y1'[x] == a y1[x], y1[0] == 1, 
    y2'[x] == -a y2[x], y2[0] == 1}, {y1, y2}, {x, -10, 10}, a];

FindRoot[{funC[a][[1]][x] == 1/E, 
  funC[a][[2]][x] == E}, {{a, 0, 1}, {x, -5, 5}}]

it gives a Part::partw error and retuns unevaluated. the following implementation gives the same results

funC1[a_, x_] := With[{temp = funC[a]}, temp[[1]][x]]
funC2[a_, x_] := With[{temp = funC[a]}, temp[[2]][x]]

FindRoot[{funC1[a, x] == 1/E, 
  funC2[a, x] == E}, {{a, 0, 1}, {x, -5, 5}}]

The answer is probably really simple, but i can't figure it out, any ideas ?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257

0 Answers0