<< Chapter < Page Chapter >> Page >

When the test at the top of the while loop determines that the previously-computed value for height was negative,

  • the body of the loop is skipped,
  • the "End Script" message is displayed, and
  • the script terminates.

This is not a complicated script in comparison with some of the scripts that were presented in earlier modules.

Given the output shown in Figure 2 , you should be able to estimate and plot the velocity of the arrow on the same graph bydividing the displacement during each time interval by the value of the time interval.

Variable velocity exercise #2

Estimating variable velocity with a computer model

Let's write a script that approximates the graphic procedure that I described above.

Copy the code from Listing 2 into an html file and open the file in your browser.

Listing 2 . Variable velocity exercise #2.

<!---------------- File JavaScript2.html ---------------------><html><body><script language="JavaScript1.3">document.write("Start Script<br/>"); //Declare and initialize constantsvar g = -32.2;//acceleration of gravity in ft/sec/sec var v0 = 100;//initial velocity in ft/secvar h0 = 6;//initial height in feet var tInc = 0.25;//calculation interval in seconds//Declare and initialize working variables var t = .0001;//current time in secondsvar h = h0;//current height in feet var v = 0;//current velocity in feet/secvar oldT = 0;//previous time in seconds var delT = 0;//change in time in secondsvar oldH = h0;//previous height in feet var delH = 0;//change in height in feet//The following variable is used to insert spaces in // the output display.var sp = "&nbsp;&nbsp;&nbsp;&nbsp;" //Compute and display various values for as long as the// height of the projectile is above the ground. while(h>0){ //This is the general equation for the height of a// projectile under the influence of gravity in a // vacuum.h = h0 + v0*t +0.5*g*t*t; //Compute and save the time interval since the// previous estimate of height, etc. delT = t-oldT;oldT = t;//Save the current time for the next iteration //Estimate the velocity based on the change in// height since the previous estimate. delH = h-oldH;v = delH/delT;//compute velocity oldH = h;//Save the current height for the next iteration.//Display the information for this iteration document.write("t = " + t.toFixed(2) + " seconds" + sp + " h = " + h.toFixed(1) + " feet" + sp +" v = " + v.toFixed(2) + " feet/second" + sp + "<br/>"); //Increment the time for the next iteration.t = t + tInc; }//end while loopdocument.write("End Script");</script></body></html>

Screen output

The text shown in Figure 4 should appear in your browser window when the html file opens in your browser.

Figure 4 . Screen output for Listing #2.
Start Script t = 0.00 seconds h = 6.0 feet v = 100.00 feet/secondt = 0.25 seconds h = 30.0 feet v = 95.97 feet/second t = 0.50 seconds h = 52.0 feet v = 87.92 feet/secondt = 0.75 seconds h = 72.0 feet v = 79.87 feet/second t = 1.00 seconds h = 89.9 feet v = 71.82 feet/secondt = 1.25 seconds h = 105.8 feet v = 63.77 feet/second t = 1.50 seconds h = 119.8 feet v = 55.72 feet/secondt = 1.75 seconds h = 131.7 feet v = 47.67 feet/second t = 2.00 seconds h = 141.6 feet v = 39.62 feet/secondt = 2.25 seconds h = 149.5 feet v = 31.57 feet/second t = 2.50 seconds h = 155.4 feet v = 23.52 feet/secondt = 2.75 seconds h = 159.2 feet v = 15.47 feet/second t = 3.00 seconds h = 161.1 feet v = 7.42 feet/secondt = 3.25 seconds h = 160.9 feet v = -0.63 feet/second t = 3.50 seconds h = 158.8 feet v = -8.68 feet/secondt = 3.75 seconds h = 154.6 feet v = -16.73 feet/second t = 4.00 seconds h = 148.4 feet v = -24.78 feet/secondt = 4.25 seconds h = 140.2 feet v = -32.83 feet/second t = 4.50 seconds h = 130.0 feet v = -40.88 feet/secondt = 4.75 seconds h = 117.7 feet v = -48.93 feet/second t = 5.00 seconds h = 103.5 feet v = -56.98 feet/secondt = 5.25 seconds h = 87.2 feet v = -65.03 feet/second t = 5.50 seconds h = 69.0 feet v = -73.08 feet/secondt = 5.75 seconds h = 48.7 feet v = -81.13 feet/second t = 6.00 seconds h = 26.4 feet v = -89.18 feet/secondt = 6.25 seconds h = 2.1 feet v = -97.23 feet/second t = 6.50 seconds h = -24.2 feet v = -105.28 feet/secondEnd Script

Questions & Answers

what is microbiology
Agebe Reply
What is a cell
Odelana Reply
what is cell
Mohammed
how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask