Solving a non-linear ODE system with ParametricNDsolveValue

Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite

I'm trying to solve a non linear ODE numerically with ParametricNDSolve, but as far as I got is shown below. My problem is to set the find root of these set of equations since I have three region, I need to match the solution between them. There might some error in my code I don't know how to match the three regions.
What I know is this: x'[0]==0, x[R]==0, x'[R]==0.
Here is my code:
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps1 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[a] == x0, x'[õ] == 0, x, x', r, õ, a, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps2 = ParametricNDSolveValue[
x''[r] + 2 x'[r] == c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3),
x[a] == x0, x'[a] == x[a], x, x', r, a, b, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps3 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[R] == 0, x'[R] == 0, x, x', r, b, R, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30]
differential-equations equation-solving parametric-functions
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
3
down vote
favorite

I'm trying to solve a non linear ODE numerically with ParametricNDSolve, but as far as I got is shown below. My problem is to set the find root of these set of equations since I have three region, I need to match the solution between them. There might some error in my code I don't know how to match the three regions.
What I know is this: x'[0]==0, x[R]==0, x'[R]==0.
Here is my code:
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps1 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[a] == x0, x'[õ] == 0, x, x', r, õ, a, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps2 = ParametricNDSolveValue[
x''[r] + 2 x'[r] == c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3),
x[a] == x0, x'[a] == x[a], x, x', r, a, b, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps3 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[R] == 0, x'[R] == 0, x, x', r, b, R, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30]
differential-equations equation-solving parametric-functions
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How do you want to combine these three solutions of three different equations? Or is this one solution of an equation with discontinuous coefficients?
â Alex Trounev
4 hours ago
It is one equations has three regions see the image.
â user60416
4 hours ago
And why in conditions $R<b$
â Alex Trounev
4 hours ago
it is R>b. I fixed it
â user60416
4 hours ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite

I'm trying to solve a non linear ODE numerically with ParametricNDSolve, but as far as I got is shown below. My problem is to set the find root of these set of equations since I have three region, I need to match the solution between them. There might some error in my code I don't know how to match the three regions.
What I know is this: x'[0]==0, x[R]==0, x'[R]==0.
Here is my code:
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps1 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[a] == x0, x'[õ] == 0, x, x', r, õ, a, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps2 = ParametricNDSolveValue[
x''[r] + 2 x'[r] == c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3),
x[a] == x0, x'[a] == x[a], x, x', r, a, b, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps3 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[R] == 0, x'[R] == 0, x, x', r, b, R, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30]
differential-equations equation-solving parametric-functions
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

I'm trying to solve a non linear ODE numerically with ParametricNDSolve, but as far as I got is shown below. My problem is to set the find root of these set of equations since I have three region, I need to match the solution between them. There might some error in my code I don't know how to match the three regions.
What I know is this: x'[0]==0, x[R]==0, x'[R]==0.
Here is my code:
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps1 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[a] == x0, x'[õ] == 0, x, x', r, õ, a, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps2 = ParametricNDSolveValue[
x''[r] + 2 x'[r] == c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3),
x[a] == x0, x'[a] == x[a], x, x', r, a, b, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ps3 = ParametricNDSolveValue[x''[r] + 2 x'[r] == c n0 Exp[-x[r]],
x[R] == 0, x'[R] == 0, x, x', r, b, R, n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30]
differential-equations equation-solving parametric-functions
differential-equations equation-solving parametric-functions
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 3 hours ago
Henrik Schumacher
39.9k255119
39.9k255119
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 4 hours ago
user60416
162
162
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user60416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How do you want to combine these three solutions of three different equations? Or is this one solution of an equation with discontinuous coefficients?
â Alex Trounev
4 hours ago
It is one equations has three regions see the image.
â user60416
4 hours ago
And why in conditions $R<b$
â Alex Trounev
4 hours ago
it is R>b. I fixed it
â user60416
4 hours ago
add a comment |Â
How do you want to combine these three solutions of three different equations? Or is this one solution of an equation with discontinuous coefficients?
â Alex Trounev
4 hours ago
It is one equations has three regions see the image.
â user60416
4 hours ago
And why in conditions $R<b$
â Alex Trounev
4 hours ago
it is R>b. I fixed it
â user60416
4 hours ago
How do you want to combine these three solutions of three different equations? Or is this one solution of an equation with discontinuous coefficients?
â Alex Trounev
4 hours ago
How do you want to combine these three solutions of three different equations? Or is this one solution of an equation with discontinuous coefficients?
â Alex Trounev
4 hours ago
It is one equations has three regions see the image.
â user60416
4 hours ago
It is one equations has three regions see the image.
â user60416
4 hours ago
And why in conditions $R<b$
â Alex Trounev
4 hours ago
And why in conditions $R<b$
â Alex Trounev
4 hours ago
it is R>b. I fixed it
â user60416
4 hours ago
it is R>b. I fixed it
â user60416
4 hours ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
This problem has a solution. It is given below
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
f[r_] := Piecewise[0, 0 <= r <= a, (3 h)/(a^3 - b^3),
a < r <= b, 0, b < r <= R]
ps = ParametricNDSolveValue[x''[r] + 2 x'[r] ==
c n0 Exp[-x[r]] + f[r], x'[0] == 0, x[0] == x0,
x, r, 0, R, n0, x0];
n =
FindRoot[ps[n0, x0][R] == 0, ps[n0, x0]'[R] == 0, n0, -.2, x0,
1]
n0 -> 9.19855*10^-8, x0 -> 0.585175
Plot[
Evaluate[Table[ps[n0, 1][r], n0, -.2, 2, .1]], r, 0, R,
PlotRange -> All],
Plot[ps[n[[1, 2]], n[[2, 2]]][r], r, 0, R]

Ah, now I get it. The third boundary condition is used to determine the parametern0. Good job (and of course +1)!
â Henrik Schumacher
13 mins ago
add a comment |Â
up vote
3
down vote
As Alex Trounev said, this is a second-order ODE with discontinuous right-hand side. You can use Piecewise to set up the forcing term:
rhs = Piecewise[
c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3), a <= r < b
,
c n0 Exp[-x[r]]
]
$$begincases frac3 ha^3-b^3+c ,textn0, e^-x(r) & aleq r<b \ c ,textn0 , e^-x(r) & textTrue endcases$$
Notice that for convenience, I used c n0 Exp[-x[r]] as the default term. The full equation can be set up as
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps = ParametricNDSolveValue[
x''[r] + 2 x'[r] == rhs,
x[R] == 0,
x'[R] == 0
,
x,
r, õ, R,
n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30
];
Solving it for a given parameter
f = ps[0.00001];
Plotting the result:
Plot[f[r], r, õ, R]

Something must be wrong in your model: The solution blows up heavily towards $r = 0$ so that x'[0] == 0 cannot be expected. Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2.
1
"Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2." - I'm actually surprised at how frequently people don't remember to check that the number of their conditions matches the order of their ODE...
â J. M. is somewhat okay.â¦
3 hours ago
@Henrik Schumacher Look at the solution from the other side at x=0
â Alex Trounev
17 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
This problem has a solution. It is given below
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
f[r_] := Piecewise[0, 0 <= r <= a, (3 h)/(a^3 - b^3),
a < r <= b, 0, b < r <= R]
ps = ParametricNDSolveValue[x''[r] + 2 x'[r] ==
c n0 Exp[-x[r]] + f[r], x'[0] == 0, x[0] == x0,
x, r, 0, R, n0, x0];
n =
FindRoot[ps[n0, x0][R] == 0, ps[n0, x0]'[R] == 0, n0, -.2, x0,
1]
n0 -> 9.19855*10^-8, x0 -> 0.585175
Plot[
Evaluate[Table[ps[n0, 1][r], n0, -.2, 2, .1]], r, 0, R,
PlotRange -> All],
Plot[ps[n[[1, 2]], n[[2, 2]]][r], r, 0, R]

Ah, now I get it. The third boundary condition is used to determine the parametern0. Good job (and of course +1)!
â Henrik Schumacher
13 mins ago
add a comment |Â
up vote
4
down vote
This problem has a solution. It is given below
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
f[r_] := Piecewise[0, 0 <= r <= a, (3 h)/(a^3 - b^3),
a < r <= b, 0, b < r <= R]
ps = ParametricNDSolveValue[x''[r] + 2 x'[r] ==
c n0 Exp[-x[r]] + f[r], x'[0] == 0, x[0] == x0,
x, r, 0, R, n0, x0];
n =
FindRoot[ps[n0, x0][R] == 0, ps[n0, x0]'[R] == 0, n0, -.2, x0,
1]
n0 -> 9.19855*10^-8, x0 -> 0.585175
Plot[
Evaluate[Table[ps[n0, 1][r], n0, -.2, 2, .1]], r, 0, R,
PlotRange -> All],
Plot[ps[n[[1, 2]], n[[2, 2]]][r], r, 0, R]

Ah, now I get it. The third boundary condition is used to determine the parametern0. Good job (and of course +1)!
â Henrik Schumacher
13 mins ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
This problem has a solution. It is given below
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
f[r_] := Piecewise[0, 0 <= r <= a, (3 h)/(a^3 - b^3),
a < r <= b, 0, b < r <= R]
ps = ParametricNDSolveValue[x''[r] + 2 x'[r] ==
c n0 Exp[-x[r]] + f[r], x'[0] == 0, x[0] == x0,
x, r, 0, R, n0, x0];
n =
FindRoot[ps[n0, x0][R] == 0, ps[n0, x0]'[R] == 0, n0, -.2, x0,
1]
n0 -> 9.19855*10^-8, x0 -> 0.585175
Plot[
Evaluate[Table[ps[n0, 1][r], n0, -.2, 2, .1]], r, 0, R,
PlotRange -> All],
Plot[ps[n[[1, 2]], n[[2, 2]]][r], r, 0, R]

This problem has a solution. It is given below
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
f[r_] := Piecewise[0, 0 <= r <= a, (3 h)/(a^3 - b^3),
a < r <= b, 0, b < r <= R]
ps = ParametricNDSolveValue[x''[r] + 2 x'[r] ==
c n0 Exp[-x[r]] + f[r], x'[0] == 0, x[0] == x0,
x, r, 0, R, n0, x0];
n =
FindRoot[ps[n0, x0][R] == 0, ps[n0, x0]'[R] == 0, n0, -.2, x0,
1]
n0 -> 9.19855*10^-8, x0 -> 0.585175
Plot[
Evaluate[Table[ps[n0, 1][r], n0, -.2, 2, .1]], r, 0, R,
PlotRange -> All],
Plot[ps[n[[1, 2]], n[[2, 2]]][r], r, 0, R]

edited 14 mins ago
answered 3 hours ago
Alex Trounev
2,535312
2,535312
Ah, now I get it. The third boundary condition is used to determine the parametern0. Good job (and of course +1)!
â Henrik Schumacher
13 mins ago
add a comment |Â
Ah, now I get it. The third boundary condition is used to determine the parametern0. Good job (and of course +1)!
â Henrik Schumacher
13 mins ago
Ah, now I get it. The third boundary condition is used to determine the parameter
n0. Good job (and of course +1)!â Henrik Schumacher
13 mins ago
Ah, now I get it. The third boundary condition is used to determine the parameter
n0. Good job (and of course +1)!â Henrik Schumacher
13 mins ago
add a comment |Â
up vote
3
down vote
As Alex Trounev said, this is a second-order ODE with discontinuous right-hand side. You can use Piecewise to set up the forcing term:
rhs = Piecewise[
c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3), a <= r < b
,
c n0 Exp[-x[r]]
]
$$begincases frac3 ha^3-b^3+c ,textn0, e^-x(r) & aleq r<b \ c ,textn0 , e^-x(r) & textTrue endcases$$
Notice that for convenience, I used c n0 Exp[-x[r]] as the default term. The full equation can be set up as
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps = ParametricNDSolveValue[
x''[r] + 2 x'[r] == rhs,
x[R] == 0,
x'[R] == 0
,
x,
r, õ, R,
n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30
];
Solving it for a given parameter
f = ps[0.00001];
Plotting the result:
Plot[f[r], r, õ, R]

Something must be wrong in your model: The solution blows up heavily towards $r = 0$ so that x'[0] == 0 cannot be expected. Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2.
1
"Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2." - I'm actually surprised at how frequently people don't remember to check that the number of their conditions matches the order of their ODE...
â J. M. is somewhat okay.â¦
3 hours ago
@Henrik Schumacher Look at the solution from the other side at x=0
â Alex Trounev
17 mins ago
add a comment |Â
up vote
3
down vote
As Alex Trounev said, this is a second-order ODE with discontinuous right-hand side. You can use Piecewise to set up the forcing term:
rhs = Piecewise[
c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3), a <= r < b
,
c n0 Exp[-x[r]]
]
$$begincases frac3 ha^3-b^3+c ,textn0, e^-x(r) & aleq r<b \ c ,textn0 , e^-x(r) & textTrue endcases$$
Notice that for convenience, I used c n0 Exp[-x[r]] as the default term. The full equation can be set up as
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps = ParametricNDSolveValue[
x''[r] + 2 x'[r] == rhs,
x[R] == 0,
x'[R] == 0
,
x,
r, õ, R,
n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30
];
Solving it for a given parameter
f = ps[0.00001];
Plotting the result:
Plot[f[r], r, õ, R]

Something must be wrong in your model: The solution blows up heavily towards $r = 0$ so that x'[0] == 0 cannot be expected. Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2.
1
"Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2." - I'm actually surprised at how frequently people don't remember to check that the number of their conditions matches the order of their ODE...
â J. M. is somewhat okay.â¦
3 hours ago
@Henrik Schumacher Look at the solution from the other side at x=0
â Alex Trounev
17 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
As Alex Trounev said, this is a second-order ODE with discontinuous right-hand side. You can use Piecewise to set up the forcing term:
rhs = Piecewise[
c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3), a <= r < b
,
c n0 Exp[-x[r]]
]
$$begincases frac3 ha^3-b^3+c ,textn0, e^-x(r) & aleq r<b \ c ,textn0 , e^-x(r) & textTrue endcases$$
Notice that for convenience, I used c n0 Exp[-x[r]] as the default term. The full equation can be set up as
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps = ParametricNDSolveValue[
x''[r] + 2 x'[r] == rhs,
x[R] == 0,
x'[R] == 0
,
x,
r, õ, R,
n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30
];
Solving it for a given parameter
f = ps[0.00001];
Plotting the result:
Plot[f[r], r, õ, R]

Something must be wrong in your model: The solution blows up heavily towards $r = 0$ so that x'[0] == 0 cannot be expected. Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2.
As Alex Trounev said, this is a second-order ODE with discontinuous right-hand side. You can use Piecewise to set up the forcing term:
rhs = Piecewise[
c n0 Exp[-x[r]] + (3 h)/(a^3 - b^3), a <= r < b
,
c n0 Exp[-x[r]]
]
$$begincases frac3 ha^3-b^3+c ,textn0, e^-x(r) & aleq r<b \ c ,textn0 , e^-x(r) & textTrue endcases$$
Notice that for convenience, I used c n0 Exp[-x[r]] as the default term. The full equation can be set up as
c = 0.72;
h = 300;
a = 15;
b = 17;
R = 25;
õ = $MachineEpsilon;
ps = ParametricNDSolveValue[
x''[r] + 2 x'[r] == rhs,
x[R] == 0,
x'[R] == 0
,
x,
r, õ, R,
n0,
Method -> "StiffnessSwitching", WorkingPrecision -> 30
];
Solving it for a given parameter
f = ps[0.00001];
Plotting the result:
Plot[f[r], r, õ, R]

Something must be wrong in your model: The solution blows up heavily towards $r = 0$ so that x'[0] == 0 cannot be expected. Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2.
answered 3 hours ago
Henrik Schumacher
39.9k255119
39.9k255119
1
"Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2." - I'm actually surprised at how frequently people don't remember to check that the number of their conditions matches the order of their ODE...
â J. M. is somewhat okay.â¦
3 hours ago
@Henrik Schumacher Look at the solution from the other side at x=0
â Alex Trounev
17 mins ago
add a comment |Â
1
"Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2." - I'm actually surprised at how frequently people don't remember to check that the number of their conditions matches the order of their ODE...
â J. M. is somewhat okay.â¦
3 hours ago
@Henrik Schumacher Look at the solution from the other side at x=0
â Alex Trounev
17 mins ago
1
1
"Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2." - I'm actually surprised at how frequently people don't remember to check that the number of their conditions matches the order of their ODE...
â J. M. is somewhat okay.â¦
3 hours ago
"Actually, you cannot prescribe more than two boundary conditions for an ODE of order 2." - I'm actually surprised at how frequently people don't remember to check that the number of their conditions matches the order of their ODE...
â J. M. is somewhat okay.â¦
3 hours ago
@Henrik Schumacher Look at the solution from the other side at x=0
â Alex Trounev
17 mins ago
@Henrik Schumacher Look at the solution from the other side at x=0
â Alex Trounev
17 mins ago
add a comment |Â
user60416 is a new contributor. Be nice, and check out our Code of Conduct.
user60416 is a new contributor. Be nice, and check out our Code of Conduct.
user60416 is a new contributor. Be nice, and check out our Code of Conduct.
user60416 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182756%2fsolving-a-non-linear-ode-system-with-parametricndsolvevalue%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password

How do you want to combine these three solutions of three different equations? Or is this one solution of an equation with discontinuous coefficients?
â Alex Trounev
4 hours ago
It is one equations has three regions see the image.
â user60416
4 hours ago
And why in conditions $R<b$
â Alex Trounev
4 hours ago
it is R>b. I fixed it
â user60416
4 hours ago