{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

practical02 - COSC 1002/1902 Computational Science in C...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COSC 1002/1902 Computational Science in C Practical 2 This practical session is concerned with floating point accuracy, the use of control structures in C, and with simple scientific problems involving solution of the quadratic equation. Before you begin these exercises, you should review the material in lecture 2. You should also download the codes in the lecture notes for lecture 2, rounding.c and quadratic.c , which are available via WebCT or from the website http://www.physics.usyd.edu.au/ wheat/cosc1002 . Compile and run the codes, following the steps outlined in the lecture notes, and confirm that you obtain the results described in the lecture notes. If you succeed with this then you are ready to begin the exercises. If not consult a tutor, who can provide assistance. The exercises are for students in both units except where indicated. Remember to get a tutor to mark off a checkpoint when you reach it. Exercises 1. As described in lecture 2, one situation where floating point rounding error can become impor- tant is when numbers with very different magnitude are added. For example, in an eight digit decimal floating point representation, 1 . 0000000 1 . 0000000 × 10 - 8 = 1 . 0000000 . (1) Hence 10 - 8 added to unity gives unity, in this representation. The machine accuracy (or machine epsilon ) is the smallest number that can be added to unity to give a number different from unity, for a given machine (computer). (a) Write a short code that prompts the user for a floating point number eps (this vari- able should have type float ), and then adds that number to 1.0 . In the code use an if-else statement to test whether the result is equal to 1.0
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern