Just something about scientific computing in Python

Attribution Non-Commercial (BY-NC)

43 views

Just something about scientific computing in Python

Attribution Non-Commercial (BY-NC)

- Computer Terms
- 08Honors Physics - Projectile Motion
- BDCDOCUMENTATION
- uniform circular motion lab
- Physics Lecture Note
- SOFTWARE SUITE FOR ACOUSTICAL CALCULATIONS SOUNDBG
- Mars 1
- GeocodingReferenceManualEnglish.pdf
- lecture-5
- Lec 2 Testing
- Embedded Systems
- Algorithms_and_Flowcharting.pdf
- BC1-2
- Lab Manual
- Untitled
- High Level Survey
- proj3(1)
- Css
- Hajsjhsk
- Lec 1-Intro to Computer

You are on page 1of 5

as of Wednesday

(or last week)

Victor Miclovich

1

y(t) = v0 t − gt2

2

The above expression that says a lot about the trajectory of a ball.

It actually computes the height of a ball in vertical motion. What if we

throw the ball with an initial velocity having an angle θ with the horizontal

”plane”?

This kind of problem has been encountered by many of you... at least if

you went to a high school physics class. The ball will follow a trajectory

y = f (x) through the air, where

1 gx2

f (x) = x tan θ − + y0

2vo2 cos2 θ

In this expression, is a horizontal coordinate... the distance in the direc-

tion of the x axis, g is the acceleration of gravity, v0 is the size1 of the initial

velocity which makes an angle θ with the x axis, and (0, y0 ) is the initial

position of the ball. Our programming goal is to make a program evaluating

equation above. The program should write out the value of all the involved

variables and what their units are.

Solution: We use the SI System and assume that v0 has been given in

km/h; g = 9.81m/s2 ; x,y, and y0 are measure in meters; and θ in degrees.

The program has got four parts; that are natural.

• Initialization of input data

1

I use size or magnitude here, velocity has speed and direction, don’t forget simple

Physics!

1

• And, finally, the evaluation of the right hand-side of the expression.

The complete program is shown below2 :

g = 9.81 #m/s**2

v0 = 15 # km/h

theta = 60 # degrees

x = 0.5 # m

y0 = 1 # m

print """\

v0 = %.1f km/h

theta = %d degrees

y0 = %.1f m\

""" % (v0, theta, y0, x)

# convert v0 to m/s

# and theta to radians:

v- = v0/3.6

theta = theta*pi/180

print ’y = %.1f m’ % y

Explanation of code

The backslash in the triple-quoted multi-line string makes the string con-

tinue on the next line without a newline. This means that removing the

backslash results in a blank line above the v0 line and a blank line between

x and y lines in t he output on the screen. Another point to note is the

expression 1/(2*v0**2), which might seem as a candidate for unintended

integer division. However, the conversion of v0 to m/s involves a division by

3.6, which results in v0 being float, and therefore 2*v0**2 being float.

2

We choose to write out all numerical values with one decimal

3

I hope to configure all these machines with PyLab (plotting), SciPy(signal and image

processing), Matplotlib (2D and 3D graphing) and Numpy (linear Algebra) packages...

so you won’t have any excuses about heavy course works when you can do things with

Python.

2

Some pointers to take note of:

Python statements

parts: the program text and a demonstration that the program works cor-

rectly.

• object: anything that a variable (name) can refer to4 (number, string,

function, module,...)

in a Python program (multiple statements on a line must be separated

by semicolons)

that results in a new object, when being evaluated

a variable (name)

4

But objects can exist without being bound to a name:print ’Hello!’ first makes a

string object of the text in quotes and then the contents of this string object, without a

name, is printed

3

How to cook the perfect egg

As an egg cooks, the proteins first denature and then coagulate. When the

temperature exceeds a critical point, reactions begin and proceed faster as

the temperature increases. In the egg white the proteins start to coagulate

for temperatures above 70◦ C. For a hard boiled egg, the center of the yolk

should be allowed to reach 70◦ C.

The following formula expresses the time t it takes (in seconds) for the

center of the yolk to reach the temperature Ty (in Celsius degrees):

2 1

M 3 cρ 3 T0 − Tw

t= 2 ln 0.76

Kπ 2 ( 4π Ty − Tw

3 )

3

density, c is the specific heat capacity, and K is thermal conductivity. Rel-

evant values are M = 47 g for a small egg and M = 67 g for a large egg,

ρ = 1.038g cm−3 , c = 3.7Jg −1 K −1 , and K = 5.4 × 10−3 W cm−1 K −1 . Fur-

thermore, Tw is the temperature (in C degrees) of the boiling water, and T0

is the original temperature (in C degrees) of the egg before being put in the

water. Implement the formula in a program, set Tw = 100 C and Ty = 70 C,

and compute t for the large egg taken from the fridge (T0 = 4 C) and from

room temperature (T0 = 20 C)5 . Name of program should be: egg.py

The piecewise constant function

0 < t < T2 ,

1,

f (x) = 0, t = T2 ,

−1, T2 < t < T

n

4X 1 2(2i − 1)πt

S(t; n) = sin

π 2i − 1 T

i=1

4 2πt 1 6πt 1 10πt

= sin + sin + sin + ...

π T 3 T 5 T

It can be shown that S(t; n) → f (t) as n → ∞. Write a program that

prints out the value of S(αT ; n) for α = 0.01, T = 2π, and n = 1, 2, 3, 4.

5

Notice that I mention two different ”original” temperatures, your code should answer

t for different values of T0

4

Let S(=S(t; n)), t, alpha, and T be variables in the program. A new S,

corresponding to a new n, should be computed by adding one term to the

previous value of S, i.e., by a statement like S=S + term. Run the program

also for α = 14 . Does the approximation S(αT ; 4) seem to be better for

α = 1/4 than for α = 0.01? Name the program file: compare fun sum.py6

What next?

Over the next weeks, months or years, we shall be looking at various engi-

neering functions, interesting mathematics and the like... just be prepared

to use this tool in your work too!

6

Email me your answers: victor.miclovich@appfrica.org

- Computer TermsUploaded byMoustafa Elbadwihi
- 08Honors Physics - Projectile MotionUploaded byelatos1234
- BDCDOCUMENTATIONUploaded byapi-3730718
- uniform circular motion labUploaded byapi-346003119
- Physics Lecture NoteUploaded byhippotamusamna
- SOFTWARE SUITE FOR ACOUSTICAL CALCULATIONS SOUNDBGUploaded byDobriyan Benov
- Mars 1Uploaded byShagun Maheshwari
- GeocodingReferenceManualEnglish.pdfUploaded byDigital Mapper
- lecture-5Uploaded bysenjics
- Lec 2 TestingUploaded byzagi tech
- Embedded SystemsUploaded byManoj Kumar
- Algorithms_and_Flowcharting.pdfUploaded byLouie De La Torre
- BC1-2Uploaded bySulalit Mohanty
- Lab ManualUploaded byIam QaXim
- UntitledUploaded byabdulkrimkhan1891
- High Level SurveyUploaded byMuhammad Rana Farhan
- proj3(1)Uploaded byyngwhi
- CssUploaded byIkee Aliangan
- HajsjhskUploaded byMD Omar Faruk
- Lec 1-Intro to ComputerUploaded byJoshua Brown
- sf04Uploaded byManish Chaturvedi
- Tutorial 8 Assembly LanguageUploaded byPrestigious Ali
- 04500140Uploaded byCésar Pesquera
- Online Judge.pdfUploaded byPedro
- Course InformationUploaded bycasio2008
- Hardware and SoftwareUploaded bybabu raj
- Unit-1Uploaded byShivay Negi
- Lecture 02Uploaded byNitish Pathak
- Contact Management SystemUploaded bySodz
- ALGORITHM.pdfUploaded byGuruprakash

- Octave programming and Linear AlgebraUploaded byVictor Miclovich
- Android Development, an introduction to developmentUploaded byVictor Miclovich
- Android Development, an introductionUploaded byVictor Miclovich
- Silly Series 1Uploaded byVictor Miclovich
- Python Hacks 4 (series)Uploaded byVictor Miclovich
- Lecture 1; PythonUploaded byVictor Miclovich
- programming in engineeringUploaded byVictor Miclovich
- Mobile apps in healthUploaded byVictor Miclovich
- Build AppsUploaded byVictor Miclovich
- Week 8Uploaded byVictor Miclovich
- Python lecture Hack03Uploaded byVictor Miclovich

- ASMR-Autonomous Sensory Meridian ResponseUploaded byGoldsteinUniv
- S1-2014-296770-bibliography (1)Uploaded byMady Ahmad
- Therapeutic Drug MonitoringUploaded byVenkatesh Gavini
- 09 - Marginal AnalysisUploaded byLyka Garcia
- Algebra II/Trigonometry Regents examUploaded byNewsday
- 2012 Aquaculture Techniques EnUploaded bylucvyho
- Pump Probe TechniqueUploaded byRaisul A. Mahmood
- Micro Exam 2Uploaded byAna Gonzalez
- 05_ Fluid Flow.pptUploaded byazira aziz
- 001a Refresher Arithmetic ElementsUploaded byFritz Natividad
- kinetoUploaded byNicoletaNico
- The Scarlet Letter by Nathaniel HawthorneUploaded byBooks
- Biodiesel Production From Palm Kernel Oil Using CalciumUploaded byifiok
- R500LC-7Uploaded byomarandrade
- Contact ProcessUploaded byOmar Almonte
- BJ30 Transistor Data sheetUploaded byAili Luggymix
- WOLF Kg Kgw Top21 1000 Ventilacijas Iekartas ENGUploaded bySladjan Ilic
- Ko1pro Plus Om Efgsj2aUploaded bytytech7
- Mukharji TSEUploaded bySam
- True or False - Nervous SystemUploaded byChloe Morningstar
- Notes_Digital-Communication-Lecture-3 Veery Good Lecture for ReviewUploaded byKashif Abbas
- Training Report - iDENUploaded bynammur85
- CA-1 PRETEST 1Uploaded byMarv Marv
- Avago+Fiber+Optic-Altera+AV00-0282EN++040714Uploaded byJaime Colvatel
- Peripherally Inserted Central Venous Catheter (PICC)Uploaded byraamki_99
- AF1 Active Audio FilterUploaded bymark777mark
- Dark Room Enlightenment - Mantak ChiaUploaded byVictoria Generao
- BFIDC and the Private Garden Owners Grow Rubber on Around 92Uploaded byabrarbd2004
- Pesticide Residues in Animal Feeds & Impact on HealthUploaded byVishnu Reddy Vardhan Pulimi
- AOAC 966.24 Grupo de Coliformes y Escherichia Coli NMPUploaded byMlian Mindiola Pablo