Mathematica Asked by Alex Stark on September 28, 2021
When I use the below script to solve an equation and plot the solution, the plot shows some discontinuous lines. For example at point $xapprox0.25$ the solver cannot find the answer and the plot is discontinuous. How can I fix this problem?
Clear["Global`*"]
c = -0.8;
L = 1;
b = Pi/L;
{x1, x2} = {0, L};
eqn = f[x] == c Sin[2 f[x]] + b x + Pi/2;
f[x_] = f[x] /.
DSolve[{D[eqn, x],
f[0] == (f0 /.
Solve[(eqn /. x -> 0 /. f[0] -> f0), f0, Reals][[1]])},
f[x], {x, x1, x2}][[1]] // FullSimplify
(*InverseFunction[-(1/2) Cos[2 #1]+#1&][(11 x)/10]*)
Plot[f[x], {x, x1, x2}]
$Version
(* "12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)" *)
Clear["Global`*"]
c = -4/5;
L = 1;
b = Pi/L;
{x1, x2} = {0, L};
eqn = f[x] == c Sin[2 f[x]] + b x + Pi/2;
The equation does not identify a unique initial condition
ic = f0 /. Solve[(eqn /. x -> 0 /. f[0] -> f0), f0, Reals]
Only one of the possible initial conditions leads to a solution
sol = Table[
DSolve[{D[eqn, x], f[0] == ic[[n]]}, f[x], {x, x1, x2}] //
FullSimplify, {n, 1, 3}] // Quiet
f[x_] = f[x] /. sol[[2, 1]];
Not all values of x
produce real results
f[0.1`15]
(* 1.0972751444995646 - 0.3208287706939249 I *)
Plotting,
Plot[f[x], {x, x1, x2},
PlotRange -> {0, 5.8},
WorkingPrecision -> 15,
Exclusions -> All,
PlotPoints -> 50,
MaxRecursion -> 2]
Answered by Bob Hanlon on September 28, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP