Skip to main content
deleted 10 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

I'd like to extend my comments to an answer. First of all, forFor those in v12 or higher, FiniteElement is the besta possible choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a littlebit more troublesome, because

  1. nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^(3/2))/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0 (* choose -1/10 if in v9 *)}] // Quiet
(* {d -> -0.0116574} *)

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}, PlotRange -> All]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^(3/2));

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]

I'd like to extend my comments to an answer. First of all, for those in v12 or higher, FiniteElement is the best choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a little troublesome, because

  1. nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^(3/2))/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0 (* choose -1/10 if in v9 *)}] // Quiet
(* {d -> -0.0116574} *)

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}, PlotRange -> All]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^(3/2));

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]

I'd like to extend my comments to an answer. For those in v12 or higher, FiniteElement is a possible choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a bit more troublesome, because

  1. nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^(3/2))/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0 (* choose -1/10 if in v9 *)}] // Quiet
(* {d -> -0.0116574} *)

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}, PlotRange -> All]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^(3/2));

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]
Typo fixed.
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

I'd like to extend my comments to an answer. First of all, for those in v12 or higher, FiniteElement is the best choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a little troublesome, because

  1. nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description hereenter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^3χ[x]^(3/2))/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0 (* choose -1/10 if in v9 *)}] // Quiet
(* {d -> -0.0116574} *)

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}], PlotRange -> All]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^3χ[x]^(3/2));

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]

I'd like to extend my comments to an answer. First of all, for those in v12 or higher, FiniteElement is the best choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a little troublesome, because

  1. nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^3/2)/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0}] // Quiet

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^3/2);

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]

I'd like to extend my comments to an answer. First of all, for those in v12 or higher, FiniteElement is the best choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a little troublesome, because

  1. nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^(3/2))/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0 (* choose -1/10 if in v9 *)}] // Quiet
(* {d -> -0.0116574} *)

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}, PlotRange -> All]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^(3/2));

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]
add FDM-based solution.
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

I'd like to extend my comments to an answer. First of all, for those in v12 or higher, FiniteElement is the best choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a little troublesome, because

  1. In these versions nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^3/2)/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0}] // Quiet

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^3/2);

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]

I'd like to extend my comments to an answer. First of all, for those in v12 or higher, FiniteElement is the best choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a little troublesome, because

  1. In these versions nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^3/2)/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0}] // Quiet

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}]

I'd like to extend my comments to an answer. First of all, for those in v12 or higher, FiniteElement is the best choice for this problem, as shown in user21's answer. But, if you're in a version lower than v12 but higher than v9, it becomes a little troublesome, because

  1. nonlinear FiniteElement isn't implemented yet.

  2. Shooting method can't handle the problem well, which is an arguable backslide.

enter image description here

As we can see, though ndsz warning is generated, NDSolve manages to find the desired result in v9.

OK, so what to do? Well, to be honest I don't know if the following solution will cause other problem in v10.0, because v10.0 is a quite unstable version, but it does work in v9 and v12.1:

rin = 10^-30;

psol = ParametricNDSolveValue[{D[χ[x], {x, 2}] == (χ[x]^3/2)/Sqrt[x], χ'[
     10] == d, χ[10] == 0}, χ, {x, rin, 10}, d]

drule = FindRoot[psol[d][rin] == 1, {d, 0}] // Quiet

Plot[psol[d /. drule][r] // Evaluate, {r, rin, 10}]

Alternatively, we can turn to finite difference method (FDM). I'll use pdetoae for the generation of finite difference equations:

rin = 0;

eq = D[χ[x], {x, 2}] Sqrt[x] == (χ[x]^3/2);

bc = {χ[rin] == 1, χ[10] == 0};

points = 25; domain = {rin, 10}; grid = Array[# &, points, domain]; difforder = 2;

del = #[[2 ;; -2]] &;
(* Definition of pdetoae isn't included in this post,
   please find it in the link above. *)    
ptoafunc = pdetoae[χ[x], grid, difforder];

ae = ptoafunc@eq // del;

initialguess[x_] = 0;

solrule = FindRoot[{ae, bc}, Table[{χ[x], initialguess[x]}, {x, grid}]]

sol = ListInterpolation[solrule[[All, -1]], grid]
[Edit removed during grace period]
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading