Launch a particle from ground level with some speed and some angle and compute the trajectory using numerical integration. This is a very simple example for those learning to program.

importmath# Constantsg=10.0# gravityv0=20.0# initial speedtheta0=math.pi/4.0# initial angledt=10.0**(-5.0)# time step######################################## Initialize simulationt=0.0# timecount=0# count for printingx=0.0# initial positiony=0.0xd=v0*math.cos(theta0)# initial velocityyd=v0*math.sin(theta0)xdd=0.0# initial accelerationydd=-g######################################## Run simulationwhiley>=0.0:# run while object in flight# numerical integration# explicit Eulerx=x+xd*dt# update position based on velocityy=y+yd*dtxd=xd+xdd*dt# update velocity based on accelerationyd=yd+ydd*dtxdd=0.0# constant acclerationydd=-gt=t+dt# advance time and countcount=count+1ifcount%1000==0:# print once every thousand simulation intervalsprintt,x,y

This discussion board is a place to discuss our Daily Challenges and the math and science
related to those challenges. Explanations are more than just a solution — they should
explain the steps and thinking strategies that you used to obtain the solution. Comments
should further the discussion of math and science.

When posting on Brilliant:

Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .

Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.

Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.

Stay on topic — we're all here to learn more about math and science, not to hear about your favorite get-rich-quick scheme or current world events.

Markdown

Appears as

*italics* or _italics_

italics

**bold** or __bold__

bold

- bulleted - list

bulleted

list

1. numbered 2. list

numbered

list

Note: you must add a full line of space before and after lists for them to show up correctly

print"import math#constantg=10.0#gravityv0=20.0#initial speedtheta0=math.pi/4.0#initial speeddt=10.0**(-5.0)#time step###########################################Initial simulationt=0.0#timecount=0#count for printingx=0.0#initial positiony=0.0xd=v0*math.cos(theta0)#initial velocityyd=v0*math.sin(theta0)xdd=0.0#initial accelerationydd=-g###############################################Run simulationwhiley>=0.0:#run while object in flight#numerical integration#elpicit eulerx=x+xd*dt#update position based on velocityy=y+yd*dtxd=xd+xdd*dt#update velocity based on accelerationyd=yd+ydd*dtxdd=0.0#constanrt accelerationt=t+dt#advance time and countcount=count+1ifcount%1000==0:#print once every thousand simulation intervalsprint(t,x,y)"

@Neeraj Anand Badgujar
–
You're welcome. And the cool part is that nowhere in the code is any parabola explicitly specified or coded. It just comes out of the numerical integration

@Steven Chase okay! thanks , can you please give me some questions or post for practicing numerical integration .
if you post it should be of E and M.
THANKS IN ADVANCE

Easy Math Editor

This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.

When posting on Brilliant:

`*italics*`

or`_italics_`

italics`**bold**`

or`__bold__`

boldNote: you must add a full line of space before and after lists for them to show up correctlyparagraph 1

paragraph 2

`[example link](https://brilliant.org)`

`> This is a quote`

Remember to wrap math in`\(`

...`\)`

or`\[`

...`\]`

to ensure proper formatting.`2 \times 3`

`2^{34}`

`a_{i-1}`

`\frac{2}{3}`

`\sqrt{2}`

`\sum_{i=1}^3`

`\sin \theta`

`\boxed{123}`

## Comments

Sort by:

TopNewest@Steven Chase thanks sir

Log in to reply

@Steven Chase sir i have also typed the the whole code ,but my code is not expressed as your code is expressed in brilliant ??

Log in to reply

You need three ticks and then "Python", and then code, followed by three more ticks

Log in to reply

Log in to reply

@Steven Chase sir can you please show a photo of your excel ,i am facing a bit of difficulty while plotting it in excel.

Log in to reply

You have to import the data from a text file and choose space-delimited format

Log in to reply

@Steven Chase i stucked here

Log in to reply

Insert - Scatter - Scatter with smooth lines

Log in to reply

@Steven Chase which option should I choose here

Log in to reply

Log in to reply

@Steven Chase which option

Log in to reply

Log in to reply

@Steven Chase now where I have to go?

Log in to reply

Insert - scatter chart - scatter with smooth lines

Log in to reply

I was going to that scatter only by mistake my arrow is at (other charts)

Log in to reply

@Steven Chase

Log in to reply

There it is

Log in to reply

@Steven Chase yes, Thank you sir

I don't think that anyone in the universe will help me like this you have helped me.

Log in to reply

Log in to reply

@Steven Chase yeah it is interesting

Log in to reply

@Steven Chase sir in the last 2nd step what is the meaning of that double equal to = = ??

Log in to reply

I single equals sign is used to declare the value of a quantity. A double equals sign is used to compare two quantities to see if they are equal

Log in to reply

@Steven Chase okay! thanks , can you please give me some questions or post for practicing numerical integration .

if you post it should be of E and M.

THANKS IN ADVANCE

Log in to reply

Wow you're such a dedicated student. Really awesome to see passion and dedication :)

Log in to reply

@Steven Chase I want to learn monte Carlo, how can I learn??

Log in to reply

Hey! You can check out this book.

Log in to reply

@Aaghaz Mahajan Thanks bro for this book

Log in to reply