0
$\begingroup$

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[0] == 2, P[0] == Pin};
pfun = ParametricNDSolveValue[{eqs, bconds}, {P, Phi}, {z, 0, 1},{a}]

How can I solve for this parameter so that $\Phi[1]$ 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, -1]]; 
pfun[x][[2]][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.

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

Are you looking for something like this?

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

Plot[Evaluate[(Phi[a][1] - 2) /. sol], {a, 10^15, 10^16}]

FindRoot[(Phi[a][1] - 2) /. sol, {a, 10^15}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.