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$
3
  • 1
    $\begingroup$ You need FindRoot[] with a good initial estimate; NSolve[] is not intended for this use. $\endgroup$ Commented Apr 11, 2017 at 0:06
  • $\begingroup$ Use EndPhi[x_? NumericQ] := (pfun = ParametricNDSolveValue[{eqs, bconds}, {P, Phi}, {z, 0, 1}, {a}]; instead $\endgroup$
    – ulvi
    Commented Apr 11, 2017 at 0:10
  • $\begingroup$ What is $\Phi_{0}$ and how is this related to $\Phi[1]$? $\endgroup$
    – zhk
    Commented Apr 11, 2017 at 1:04

1 Answer 1

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 and acknowledge you have read our privacy policy.

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