# Solving a specific initial value problem

**URL:** <https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236>\
**Category:** Questions\
**Tags:** calculus, equation-solving, numerical-computation\
**Created:** [June 19, 2023, 7:57am UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236 "2023-06-19T07:57:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![e11925883](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@e11925883](https://community.wolfram.com/u/e11925883)\
**Post date:** [June 19, 2023, 7:57am UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236/1 "2023-06-19T07:57:19Z")

</div>

Hi,  
I am completely new to Mathematica and I really need some advice on solving a specific initial value problem numerically.

The differential equation is: θ’'[x] - p^2 sin[2θ[x]] == 0 , x = {0,1}

for p = π/(2 Sqrt[2])

The initial values are θ’[0] == 0; θ[0] == {0, 2π}.

So I need to solve the equation for various initial angles θ[0] from 0 to 2π

Ι tried it with a For-Loop, but it is not working.  
I would like to get a list of angles θ[1] after solving the equation for different initial angles θ[0]  
I need to plot the angle θ[0] over the resulting angle θ[1].

Thanks for your help!

[Question.nb](https://community.wolfram.com/uploads/short-url/y0xyiJ5FDpGVZmtQvJoGrvfHuVB.nb) (2.97 KB)

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [June 19, 2023, 10:57am UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236/2 "2023-06-19T10:57:02Z")

</div>

You cannot use `\[Theta]_entry` as a variable name, it is a pattern. I would do it this way:

```
sol[t0_] := NDSolveValue[
   {\[Theta]''[x] - (\[Pi]/(2 Sqrt[2]))^2 Sin[2 \[Theta][x]] == 0,
    \[Theta][0] == t0, \[Theta]'[0] == 0}, \[Theta], {x, 0, 1}];
Table[{t0, sol[t0][1]},
 {t0, 0, 2 Pi, 0.125 Pi}]

```

---

<div class="post-metadata">

**Author:** ![rolandfranzius](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@rolandfranzius](https://community.wolfram.com/u/rolandfranzius)\
**Post date:** [June 19, 2023, 11:36am UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236/3 "2023-06-19T11:36:23Z")

</div>

This is the mathematical pendulum equation for the oscillatory case.

Mathematica solves it directly, but the form of the solution is a bit weird, because the Jacobi amplitude is primarily defined for rotational modes with veloctiy :\>0 at [Theta] = Pi,.

```
    DSolveValue[\[Theta]''[t] - \[Pi]^2/8 Sin[2 \[Theta][t]] == 0 , \[Theta][t], t] 

 JacobiAmplitude[(I Sqrt[\[Pi]^2-8 C[1] (t+C[2]))/(2 Sqrt[2]),(2 \[Pi]^2)/(\[Pi]^2-8 C[1])]

```

Its nearly impossible to include the start condtions. As the equation is time independent, one constant C[1](https://de.wikipedia.org/wiki/Mathematisches_Pendel#Exakte_L%C3%B6sung) is simply the start time and has be set so to meet the start conditions together with .the second constant,determines the velocity at t=-C[2] , that is in the lower dead point.

```
      D[JacobiAmplitude[(I Sqrt[\[Pi]^2 - 8 C[1]] (t + C[2]))/(2 Sqrt[2]), ( 2 \[Pi]^2)/(\[Pi]^2 - 8 C[1])], t] /. {t + C[2] -> 0}

      \Omega = (I Sqrt[\[Pi]^2 - 8 C[1]])/(2 Sqrt[2]) -> (Sqrt[8 C[1]]-\[Pi]^2 )/(2 Sqrt[2]) 

```

We know that the total energy is conserved

```
   [Theta]'[t] [Theta]''[t] - \[Pi]^2/8 [Theta]'[t] Sin[2 \[Theta][t]] == 0 -->
    1/2 [Theta]'[t] ^2 +\[Pi]^2/16 ( 1- Cos[2 \Theta] = W = const

```

From this equation it is possible to solve for C[1](https://de.wikipedia.org/wiki/Mathematisches_Pendel#Exakte_L%C3%B6sung) in terms of Theta

Because of the poor state of implementation of the elliptic function complex in Mathematica, most work has to be done by hand. The rather trival solution can be found in [Pendel exakte Lösung](https://de.wikipedia.org/wiki/Mathematisches_Pendel#Exakte_L%C3%B6sung)

---

<div class="post-metadata">

**Author:** ![e11925883](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@e11925883](https://community.wolfram.com/u/e11925883)\
**Post date:** [June 19, 2023, 4:22pm UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236/4 "2023-06-19T16:22:28Z")

</div>

Thanks for your reply.

I have another problem, which is even more basic. If I want to solve the differential equation from above for some random initial value problem (let’s leave the For-Loop behind and concentrate only on one specific solution), Mathematica always replies with the same error response:

Why is that so??

 ![Bildschirm­foto 2023-06-19 um 18.29.40.jpg](https://global.discourse-cdn.com/wolfram/original/3X/e/6/e67fed46889d4bfcadb5b46e3efdb0ac3c8aaf6d.jpeg)

---

<div class="post-metadata">

**Author:** ![e11925883](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@e11925883](https://community.wolfram.com/u/e11925883)\
**Post date:** [June 19, 2023, 4:27pm UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236/5 "2023-06-19T16:27:30Z")

</div>

In this case it is no pendulum equation, but an equilibrium condition for a rod in a crooked channel with an asymmetric cross-section. There is no oscillation going on.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [June 19, 2023, 5:36pm UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236/6 "2023-06-19T17:36:24Z")

</div>

The following works fine for me, although with a different answer:

```
Clear[x];
p = Pi/(2 Sqrt[2]);
dgl = \[Theta]''[x] - p^2 Sin[2 \[Theta][x]] == 0;
sol = NDSolve[{dgl, \[Theta][0] == Pi/2, \[Theta]'[0] == 
    0}, \[Theta], {x, 0, 1}]
entry = \[Theta][1] /. sol[[1]]

```

I cannot reproduce the error you get, but it is _similar_ to what we happens when the independent variable of a differential equation is given a value before `NDSolve` is called:

```
x = 0;
NDSolve[{f'[x] == 1, f[0] == 0}, f, {x, 0, 1}]

```

The variables f, x are not automatically protected from outside interference. However, in your case there must be something else going on.

---

<div class="post-metadata">

**Author:** ![rolandfranzius](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@rolandfranzius](https://community.wolfram.com/u/rolandfranzius)\
**Post date:** [June 19, 2023, 5:59pm UTC](https://community.wolfram.com/t/solving-a-specific-initial-value-problem/22236/7 "2023-06-19T17:59:02Z")

</div>

Sorry, yes, there is a minus sign. But except for an x → i t the algebra is all the same. One is in the uncharted area of the elliptic amplitude unforunately.
