Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SciProg2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pclark3
SciProg2024
Commits
16429e25
Commit
16429e25
authored
1 year ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
19adf9ca
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CodeExamples/FlightPlot.ipynb
+82
-0
82 additions, 0 deletions
CodeExamples/FlightPlot.ipynb
with
82 additions
and
0 deletions
CodeExamples/FlightPlot.ipynb
0 → 100644
+
82
−
0
View file @
16429e25
{
"cells": [
{
"cell_type": "markdown",
"id": "d05a32dc",
"metadata": {},
"source": [
"# Flight Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7947b211",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
" Form a plot the flight of a particle given initial velocity \n",
" and acceleration\n",
"\"\"\"\n",
"import math\n",
"import matplotlib.pyplot as plt # Import the plot package as plt\n",
"\n",
"def distance(u,a,t):\n",
" \"\"\"\n",
" Function to calculate distance\n",
" \"\"\"\n",
" x = u*t + 0.5*a*t**2 # Calcualte distance\n",
" return x # Return distance\n",
"\n",
"def main():\n",
" u = float(input(\"Initial velocity : \"))\n",
" a = float(input(\"Acceleration : \"))\n",
" maxTime = float(input(\"Maximum time : \"))\n",
" \n",
" plot_points = 100 # Number of point\n",
" increment = maxTime/plot_points # Increment between points\n",
"\n",
" t_data = [] # lists to hold the data\n",
" x_data = []\n",
"\n",
" for i in range(0,plot_points): # Start of loop\n",
" t = increment*i # Time\n",
" x = distance(u,a,t) # Get distance\n",
" t_data.append(t) # Append to t list\n",
" x_data.append(x) # Append to x list\n",
"\n",
"\n",
" plt.plot(t_data,x_data,\"g\") # Default plot in green\n",
" plt.title(\"Flight of particle\") # Add title/lables\n",
" plt.xlabel(\"Time\")\n",
" plt.ylabel(\"Distance\")\n",
" plt.show() # show the actual plot\n",
"\n",
"\n",
"main()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:markdown id:d05a32dc tags:
# Flight Plot
%% Cell type:code id:7947b211 tags:
```
python
"""
Form a plot the flight of a particle given initial velocity
and acceleration
"""
import
math
import
matplotlib.pyplot
as
plt
# Import the plot package as plt
def
distance
(
u
,
a
,
t
):
"""
Function to calculate distance
"""
x
=
u
*
t
+
0.5
*
a
*
t
**
2
# Calcualte distance
return
x
# Return distance
def
main
():
u
=
float
(
input
(
"
Initial velocity :
"
))
a
=
float
(
input
(
"
Acceleration :
"
))
maxTime
=
float
(
input
(
"
Maximum time :
"
))
plot_points
=
100
# Number of point
increment
=
maxTime
/
plot_points
# Increment between points
t_data
=
[]
# lists to hold the data
x_data
=
[]
for
i
in
range
(
0
,
plot_points
):
# Start of loop
t
=
increment
*
i
# Time
x
=
distance
(
u
,
a
,
t
)
# Get distance
t_data
.
append
(
t
)
# Append to t list
x_data
.
append
(
x
)
# Append to x list
plt
.
plot
(
t_data
,
x_data
,
"
g
"
)
# Default plot in green
plt
.
title
(
"
Flight of particle
"
)
# Add title/lables
plt
.
xlabel
(
"
Time
"
)
plt
.
ylabel
(
"
Distance
"
)
plt
.
show
()
# show the actual plot
main
()
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment