# Solve for parameter in ParametricNDSolve

I have a simple 2-variable ODE system with a parameter

$P'[z] = -2\Phi[z]$

$\Phi'[z] = -2\frac{P[z]}{a}$

I've implemented the code as follows

Pin = 20*10^5;

eqs = {P'[z] == -Phi[z], Phi'[z] == -Phi[z]/a};
bconds = {Phi == 2, P == Pin};
pfun = ParametricNDSolveValue[{eqs, bconds}, {P, Phi}, {z, 0, 1},{a}]


How can I solve for this parameter so that $\Phi$ is given by a specific $\Phi_{0}$. I've tried to define an inline function

EndPhi[x_] := (pfun = ParametricNDSolveValue[{eqs, bconds}, {P, Phi}, {z, 0, 1}, {a}];
xEnd = pfun[x][][[1, 1, -1]];
pfun[x][][xEnd]);


When I use

NSolve[EndPhi[x] == 0.2,x]


This does not lead to the solution. However, EndPhi[x] yields numbers for input values.

• You need FindRoot[] with a good initial estimate; NSolve[] is not intended for this use. – J. M. is in limbo Apr 11 '17 at 0:06
• Use EndPhi[x_? NumericQ] := (pfun = ParametricNDSolveValue[{eqs, bconds}, {P, Phi}, {z, 0, 1}, {a}]; instead – ulvi Apr 11 '17 at 0:10
• What is $\Phi_{0}$ and how is this related to $\Phi$? – zhk Apr 11 '17 at 1:04

sol = ParametricNDSolve[{eqs, bconds}, {P, Phi}, {z, 0, 1}, {a}];