New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: Walker Witting


Marketplace > Rice University > Applied Mathematics > CAAM 420 > COMPUTATIONAL SCIENCE I
Walker Witting
Rice University
GPA 3.58

Timothy Warburton

Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Timothy Warburton
Class Notes
25 ?




Popular in Course

Popular in Applied Mathematics

This 16 page Class Notes was uploaded by Walker Witting on Monday October 19, 2015. The Class Notes belongs to CAAM 420 at Rice University taught by Timothy Warburton in Fall. Since its upload, it has received 17 views. For similar materials see /class/224995/caam-420-rice-university in Applied Mathematics at Rice University.

Similar to CAAM 420 at Rice University




Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/19/15
Computational Science I Lecture 6 CAAM 420 Fall 2004 Instructor Tim Warburton while loops We can also construct less rigid loops A looser stucture is whilecompletion test is true body The Sum Example Using while We initialize the iloop variable outside the while loop and increment it inside the while loop to achieve the same effect as the for loop Buffers Files TODIS EJt Search mule C Hell 1nclude ltStd10hgt main initialize an index variabl in 7 int iloop l initialize my accumalting variable imycounter int 1mycounter 0 whi e1loop lt l00 imycounter 1mycounter1loopz iloop ilooplz printf sum of numbers from 1 to 100 is dn imycounter Using break We sometimes would like to break out of a for or while loop before the conditional test is made Buffers Files Tools 1 ncl ude ltstcl10 hgt 1 ncl ude ltmath hgt mai n 7 initialize some int iloop int in l initialize my double dmycounter whileCiloop lt 100 adg sum of co 1nlt1 dmycounter cos031nMPI for 1n0 dmycounter if dymcounter if dmycounter gt pri ntfquotbreaki break iloop iloopl pri ntf dmycounter accumulating variable dmycounter o Ed139t Search Mule c Hel int variables mai n initialize some int variables int iloop 1 1m 1n v 00 quot initialize my accumulating variable dmycounter s03quotir1pifor in0iloop to dmycount dOUble deCOUI ltequot 0 loop II39I 1nl whileCiloop lt 10000 quot add sum of cos03quotinpi for in0iloop to dmycounter forC in0 inltiloop in inl dmycounter dmycounter cos03 inMPI is large 100 ng loop at iloopdn iloop exit the loop maan 1 p 1715fn dmycounter Hoopl pri ntf dmycounter l715fn dmycounter Some Notes on mvbreakc Here used a function call to cos and referred to MPl Believe it or not this is not part of the default C language 80 at the top of the file I included mathh AND when I compiled I linked in libma because this includes the cos function A gt gt gcc o mybreak mybreakc gt gt mybreak breaktng loop at iloop196 dmicounter 100194265251835333 gt What happens if we don t take care of COSf 2 Suppose I do not include mathh H EI Quick Connect El Profiles gt gt gcc o mybreak mybreakc lm mybreakc In function main39 mybreakcl6 warning type mismatch in implicit d eclaration for built in function cos39 mybreakc16 MPI39 undeclared first use in this function mybreakc16 Each undeciared identifier is repor ted only once mybreakc16 for each function it appears in gtI 1 The compiler complains that it has no idea what the cos function is or what the variable MPl is and stops without completing the compile cont Suppose I forget to link in Le include Im on the compile line but do remember to include mathh J gcc o mybreak mybreakc Undefined first referenced symbol in fiie cos vartmpchAa aRJlo id fatal Symbol referencing errors No output wr itten to mybreak gtv The compiler tells us it can t find the cos function definition That s why we have to tell the compiler to include libma by adding m if We can take choose what lines of code should be executed based on a logical test Suppose I want to print out a message which changes depending on whether a variable is odd or even First I need to construct a test to see if the number is odd and even then I need to direct the execution towards one of two different commands Demo of if Here we check to see if a variable is even or odd and print out an appropriate message Muie C He purpose demo the if structure inciude ltstdiohgt main int iA 4 test to see if iA is even or odd C is the moduio operator if iA 2 0 D f ie if iA moduio 2 equaislzero printf n iAd is even nn iA eise 339 gcc o myif myi Fc AAAA printf n iAd is odd nnquot iA 39 myif iA4 is even ll A gt39 Flow Control Summary We have now seen how to construct repetitive behavior using M loops or while loops We have seen how to exit a loop prematurely using break We can now control which lines of code are executed with the if statement We did not mention goto under no circumstances are you to ever hand in homework including gotol Later on we will discuss the switchcase construction doEmE Variables Memory When you create an int int ia You are actually requesting a block of memory We can find out how many bytes you are requesting with the C operator sizeof Using sizeof Invoking sizeof with an argument which is the type of variable you wish to find the size of in bytes returns an integer value Til rufriteedu A ruf A 55H 52ure Shell 5 H Elle Edit iiew window elp l Juleolnel eeelmlemlelewl H E QuickCnnnect Profiles 139 f purpose to display list of sizes for common variable types include lt5tdiohgt Display the number of bytes required to store a char or int or float or double This information is returned from the Sizeof function printf A char occupies d bytes of memoryn sizeofchar printf An int occupies d bytes of memoryn sizeofCintDD printf A float occupies d bytes of memoryn sizeofoloatDD printf A double occupies d bytes of memoryn sizeodeoubleDD Connected to rufrieledu lSSHZ aeleB Lbc hmacmdS none l 75x20 I I I l A Using sizeof cont This is the answer on ruf beware this could be different on a different machine ie never assume Ln gcc o mysizeof mysizeofc mysizeof char occupies 1 bytes of memory An int occupies 4 bytes of memory A fioat occupies 4 bytes of memory A doubie occupies 8 bytes of memory gt Arrays of Variables In addition to creating space for a single variable we can also request space for a set of variables For instance suppose we wish to store a set of int s We can use calloc to perform this task Properly invoked calloc will return a pointer to a piece of memory sufficient for our needs


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Janice Dongeun University of Washington

"I used the money I made selling my notes & study guides to pay for spring break in Olympia, Washington...which was Sweet!"

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.