Skip to main content
added 631 characters in body
Source Link
zhk
  • 12k
  • 1
  • 23
  • 39

This is more like a comment.

You have a discontinuous ode, so to turn off the discontinuity during NDsolve's processing of your ode with DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

Edit

By now, we are sure that NDSolve has problems with DiracDelta. So there is another way to deal with it by approximating it by a NormalDistribution,

e1=0.00001;
p1 = NDSolve[{f''[x] == 
    PDF[NormalDistribution[10, e1], x] zf/(ep a^2) - 
     1 Sum[z[i] cp[i], {i, 1, 2}], f[10] == zf/(ep a^2), f'[20] == 0},
   f, {x, 10, 100}, MaxStepSize -> e1, 
  MaxSteps -> Infinity]

Finally, plotting the two results combine,

Show[Plot[f[x] /. p, {x, 10, 100}], 
 Plot[f[x] /. p1, {x, 10, 100}, PlotStyle -> {Dashed, Red}]]

enter image description here

Apparently, both numerical solutions p and p1 are identical.

This is more like a comment.

You have a discontinuous ode, so to turn off the discontinuity during NDsolve's processing of your ode with DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

This is more like a comment.

You have a discontinuous ode, so to turn off the discontinuity during NDsolve's processing of your ode with DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

Edit

By now, we are sure that NDSolve has problems with DiracDelta. So there is another way to deal with it by approximating it by a NormalDistribution,

e1=0.00001;
p1 = NDSolve[{f''[x] == 
    PDF[NormalDistribution[10, e1], x] zf/(ep a^2) - 
     1 Sum[z[i] cp[i], {i, 1, 2}], f[10] == zf/(ep a^2), f'[20] == 0},
   f, {x, 10, 100}, MaxStepSize -> e1, 
  MaxSteps -> Infinity]

Finally, plotting the two results combine,

Show[Plot[f[x] /. p, {x, 10, 100}], 
 Plot[f[x] /. p1, {x, 10, 100}, PlotStyle -> {Dashed, Red}]]

enter image description here

Apparently, both numerical solutions p and p1 are identical.

Made English more idiomatic
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

This is more like a comment.

You have a discontinuesdiscontinuous ode, so to turn off the discontinuity during NDsolve's processing of your ode, we can use with DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

This is more like a comment.

You have a discontinues ode, so to turn off the discontinuity during NDsolve processing your ode, we can use DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

This is more like a comment.

You have a discontinuous ode, so to turn off the discontinuity during NDsolve's processing of your ode with DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

added 14 characters in body
Source Link
zhk
  • 12k
  • 1
  • 23
  • 39

This is more like a comment.

You have a discontinues ode, so to turn off the discontinuity during NDsolve processing your ode, we can use DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

This is more like a comment.

You have a discontinues ode, so to turn off the discontinuity during NDsolve processing your ode, we can use DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

This is more like a comment.

You have a discontinues ode, so to turn off the discontinuity during NDsolve processing your ode, we can use DiscontinuityProcessing,

NDSolve[{f''[x]==DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}],
f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100},
Method -> {"DiscontinuityProcessing" -> False}]

which generate this error,

NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 10.`.

So I added a submethod Method -> "ExplicitEuler"

p = NDSolve[{f''[x] == 
  DiracDelta[-10 + x] zf/(ep a^2) - 1 Sum[z[i] cp[i], {i, 1, 2}], 
  f[10] == zf/(ep a^2), f'[20] == 0}, f, {x, 10, 100}, 
  Method -> {"FixedStep", Method -> "ExplicitEuler", 
  "DiscontinuityProcessing" -> False}]

which produced a solution but with a warning,

NDSolve::nlnum: The function value {-0.0000234567,2.5*10^-6+0.00125 DiracDelta[0.]} is not a list of numbers with dimensions {2} at {x,f[x],(f^[Prime])[x]} = {10.,0.00125,-0.0000234567}.

Plot[f[x] /. p, {x, 10, 100}]

enter image description here

Source Link
zhk
  • 12k
  • 1
  • 23
  • 39
Loading