(3) Intro to Fortran

(3) Intro to Fortran - PROGRAM hello IMPLICIT NONE !This is...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Nathan Friedman 2009 PROGRAM hello IMPLICIT NONE !This is my first program WRITE (*,*) “Hello World!” END PROGRAM hello s 2009 s Introduction to FORTRAN s 2 1. The program block 2. Case sensitivity 3. Comments 4. Output s 2009 s Introduction to FORTRAN s 3 Here’s a classical problem that arises in many applications. Problem: Find the roots of the quadratic ax 2 +bx+c s 2009 s Introduction to FORTRAN s 4 t This problem, and partial solutions are mentioned over 3500 years ago. We use an algorithm developed in India in the 8th century t The roots are given by the formula s 2009 s Introduction to FORTRAN s 5 a ac b b 2 4 2 - ± - First we focus on computing the discriminant b 2 -4ac We will develop an algorithm for finding the result The algorithm should work for any value of a, b and c. That is, it should be generic s 2009 s Introduction to FORTRAN s 6
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 t The values a, b and c are called variables since they can take on any numeric value. t In Fortran, variables represent memory cells. They are names of memory locations. t Each cell can store a single value at any given time. s 2009 s Introduction to FORTRAN s 7 t The values of variables like a, b and c must be stored in the memory cells s 2009 s Introduction to FORTRAN s 8 t The values of variables like a, b and c must be stored in the memory cells t They can be input from outside the program s 2009 s Introduction to FORTRAN s 9 t The values of variables like a, b and c must be stored in the memory cells t They can be input from outside the program t Assignment statements can be used to tell the computer to place values in these cells s 2009 s Introduction to FORTRAN s 1 0 t We can use the values stored in variables and perform basic operations such as +, -, *, /, etc. on them t We can store the result of an operation into a memory cell t We can output the value to the screen or printer s 2009 s Introduction to FORTRAN s 1 1 t Back to our problem of computing b 2 -4ac s 2009 s Introduction to FORTRAN s 1 2
Background image of page 2
3 t Back to our problem of computing b 2 -4ac t A psuedocode algorithm input a, b, c x <- b * b y <- a * c z <- 4 * y d <- x - z s 2009 s Introduction to FORTRAN s 1 3 t Algorithms are generic – that is, they must
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

(3) Intro to Fortran - PROGRAM hello IMPLICIT NONE !This is...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online