0
$\begingroup$

When I use the below script to solve an equation and plot the solution, the plot shows some discontinuous lines. For example at point $x\approx0.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}]
$\endgroup$
1
  • $\begingroup$ Plot does not plot complex numbers. With your code f[0.1]=1.09728 -0.320829 I. You can choose to plot the real part with Re[f[x]] $\endgroup$
    – Bill Watts
    Commented Jun 27, 2020 at 20:38

1 Answer 1

1
$\begingroup$
$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]

enter image description here

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

enter image description here

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]

enter image description here

$\endgroup$
2
  • $\begingroup$ I had tried to find coefficients $c_1$ and $c_2$ myself so that $\sin(2f(x=0))=\sin(2f(x=L))$ and also $\cos(2f(x=0))=\cos(2f(x=L))$ $\endgroup$
    – Alex Stark
    Commented Jun 28, 2020 at 3:25
  • $\begingroup$ Do not ask new questions in comments. Organize your thoughts and post a new question with all pertinent information. Then anyone who is interested will see the new question. $\endgroup$
    – Bob Hanlon
    Commented Jun 28, 2020 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.