Problems solving this differential equation for a Pendulum with Mathematica

Click For Summary
SUMMARY

The discussion focuses on solving a differential equation for a pendulum using Mathematica. The user encountered issues with initial conditions while using the NDSolve and DSolve functions. Specifically, the error arose from incorrect initial conditions, where both phi[0] were set to different values. The solution involved correcting the initial conditions and utilizing the Plot function with legends to differentiate between the exact and approximate solutions.

PREREQUISITES
  • Familiarity with Mathematica 12.0 syntax and functions
  • Understanding of differential equations and boundary conditions
  • Knowledge of NDSolve and DSolve functions in Mathematica
  • Basic plotting techniques in Mathematica, including the use of PlotLegends
NEXT STEPS
  • Explore advanced features of NDSolve in Mathematica for complex differential equations
  • Learn about the use of boundary conditions in differential equations
  • Investigate the differences between NDSolve and DSolve in Mathematica
  • Study plotting techniques in Mathematica, focusing on customizing legends and annotations
USEFUL FOR

Mathematica users, students studying differential equations, and anyone interested in visualizing mathematical solutions through plotting techniques.

Lambda96
Messages
233
Reaction score
77
TL;DR
Mathematica does not solve the differential equations
Hi,

unfortunately, I have problems that Mathematica does not solve the differential equation. The task is as follows and it is about the task c

Bildschirmfoto 2023-06-28 um 18.54.02.png


In the Mathematica Notebook, the following was written for task c

"You can use the following two lines of code to produce the solutions of the exact and approximated differential equations with boundary conditions. After that, write a plot[ ] function to sketch the two together."

exact[t_] := Evaluate[phi[t] /. NDSolve[..., phi[t], {t, 0, 20}]];
approx[t_] := Evaluate[phi[t] /. DSolve[..., phi[t], t]];I then tried to calculate the differential equation for equation (4) using the two codes and got the following

Bildschirmfoto 2023-06-28 um 18.58.49.png

I then tried solving the differential equation using only NDSolve and get the following.

Bildschirmfoto 2023-06-28 um 19.04.34.png

I am a beginner in Mathematica, so I do not know what I have done wrong in the two formulas?
 
Physics news on Phys.org
As the error messages say, your initial conditions are wrong. You have
Code:
phi[0]==0
and
Code:
phi[0]==Pi/2
which is not meaningful. You should have the first derivative of phi for one of those.
Code:
phi'[0]==...
 
Thanks Dale for your help and for looking over my code 👍

I have now tried plotting the differential equations again, but this time with phi'[0]=0 and with ##\gamma=0.1## and got the following.

Bildschirmfoto 2023-06-28 um 21.44.11.png

Is there any way that I can show in the plot which function is which?
 
Lambda96 said:
Is there any way that I can show in the plot which function is which?
There are different options. Try for instance
Code:
Plot[{exact[t],approx[t]},{t,0,20},PlotLegends->"Expressions"]
 
Thanks DrClaude for your help, this is exactly what I was looking for 👍
 
  • Like
Likes   Reactions: berkeman

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K