I am trying to solve the following set of differential eqiations
$\qquad y''(x) + a\,\sin(x) z(x) = 0 \quad z''(x) + a\,z(x) y(x) = 0$
where $a$ is a parameter. I want to get a solution for many values ofd $a$, so I constructed something like the following (I didn't want to use ParametricNDSolve
as the actual equation I need to solve is stiff as well as I need to solve some algebraic equation in terms of solutions to find out a specific $a$)
{y1[a_?NumericQ], z1[a_?NumericQ]} :=
{y1[a],
z1[a]} = {y, z} /.
NDSolve[
{y''[x] + a*Sin[x] z[x] == 0, z''[x] + a*z[x]
y[x] == 0, y[0] == 0, z[0] == 0, y'[0] == -0.1, z'[0] == 0.05},
{y, z}, {x, 0, 10}] // First
I have used these type of functionalized constructs for single differential equation, but in this case of system of equations the following error is showing
SetDelayed::shape: Lists {y1[a_?NumericQ],z1[a_?NumericQ]} and {y1[a],z1[a]}=First[{y,z}/. NDSolve[{(<<1>>^(<<1>>))[<<1>>]+Times[<<3>>]==0,(<<1>>^(<<1>>))[<<1>>]+Times[<<3>>]==0,y[0]==0,z[0]==0,(y^[Prime])[0]==-0.1,(z^[Prime])[0]==0.05},{y,z},{x,0,10}]] are not the same shape. >>
How can I solve the problem? Please help.
ParametricNDSolveValue
? $\endgroup$Method -> "StiffnessSwitching"
. $\endgroup$//
issue, usingFirst[]
also yields the same error. $\endgroup$First
. The problem is that there are in fact two separate definitions, and they must be independent. I would have a single function that returns two values, or similar, if I really wanted memoization. $\endgroup$ParametricNDSolveValue
not work with"StiffnessSwitching"
? I just tried it and it worked fine. Furthermore, it seems to support solution caching too, which means that you do not need memoization. $\endgroup$