0 views

Uploaded by Vinay Gupta

hydraulics

- Parameter Template 3G
- Nesoft Configuration Command Line Reference (1)
- Zai 00005
- C++ Ders3 - Fonksiyonlar
- Functions in SQL Server Practical Guide
- Pro-e Drawing Sys Parameter Dwg
- [Series in Computational Physics] David J. Pine - Introduction to Python for Science and Engineering (2019, CRC Press).pdf
- Chapter-09_Overview-of-Search-Helps.ppt
- MXnet
- Computer Science Set 2
- PYT String Formatting
- plantserviceandcheckers c
- VFD
- HC900 Function Block
- 14229
- DieQuote_Generator.pdf
- Sap Workflow Tutorial
- About an approximate formula for scattering amplitude by a disc
- CH05 Query - Rules That Apply to Queries and to Their Responses
- crank&camdescription.pdf

You are on page 1of 5

Arrays

AUTUMN 2004

PROGRAM DOLOOPS IMPLICIT NONE INTEGER I

Fortran

Week 2 - 1

David Apsley

Example 1.2 Different types of DO-Loop Newtons method for square roots: x n +1 = ( x n + (i) Deterministic DO loop

PROGRAM NEWTON IMPLICIT NONE REAL A REAL X INTEGER N PRINT *, 'Enter a number' READ *, A X = 1.0 DO N = 1, 10 X = 0.5 * ( X + A / X ) PRINT *, X END DO END PROGRAM NEWTON

1 2

A ) xn

! value whose square root is to be found ! current estimate of square root ! a counter

PROGRAM NEWTON IMPLICIT NONE REAL A ! value whose square root is to be found REAL X, XLAST ! current and previous estimate of root REAL, PARAMETER :: TOLERANCE = 1.0E-6 ! tolerance for convergence PRINT *, 'Enter a number' READ *, A X = 1.0 DO XLAST = X X = 0.5 * ( X + A / X ) ! update answer PRINT *, X IF ( ABS( X - XLAST ) / X < TOLERANCE ) EXIT END DO END PROGRAM NEWTON

(iii) DO WHILE

PROGRAM NEWTON IMPLICIT NONE REAL A ! value whose square root is to be found REAL X, XLAST ! current and previous estimate of root REAL, PARAMETER :: TOLERANCE = 1.0E-6 ! tolerance for convergence PRINT *, 'Enter a number' READ *, A X = 1.0 XLAST = X * 100.0

! initial guess - anything non-zero ! anything that isn't close to X ! criterion for continuing

DO WHILE ( ABS( X - XLAST ) / X > TOLERANCE ) XLAST = X X = 0.5 * ( X + A / X ) PRINT *, X END DO END PROGRAM NEWTON

Fortran

Week 2 - 2

David Apsley

PROGRAM POWER_SERIES IMPLICIT NONE REAL, EXTERNAL :: NEW_EXP REAL VALUE ! declare a function we shall use ! number to test

PRINT *, 'Enter a number' READ *, VALUE PRINT *, 'Sum of series = ', NEW_EXP( VALUE ) ! our own function PRINT *, 'Actual EXP(X) = ', EXP( VALUE ) ! library routine END PROGRAM POWER_SERIES

!===============================================

REAL FUNCTION NEW_EXP( X ) ! X X**2 X**3 ! Power series: NEW_EXP(X) = 1 + --- + ---- + ---- + ... ! 1! 2! 3! IMPLICIT NONE REAL X INTEGER N REAL TERM REAL, PARAMETER :: TOLERANCE = 1.0E-07 ! ! ! ! argument of function number of a term a term in the series truncation level

NEW_EXP = TERM

! first term

! Add successive terms until they become negligible DO WHILE ( ABS( TERM ) > TOLERANCE ) ! criterion for continuing N = N + 1 ! index of next term TERM = TERM * X / N ! new term is a multiple of last NEW_EXP = NEW_EXP + TERM ! add to sum END DO END FUNCTION NEW_EXP

Fortran

Week 2 - 3

David Apsley

PROGRAM EXAM IMPLICIT NONE INTEGER MARK CHARACTER GRADE

DO WRITE ( *, '("Enter mark (negative to end): ")', ADVANCE = 'NO' ) READ *, MARK IF ( MARK < 0 ) STOP ! program ends if a negative value is input IF ( MARK >= 70 ) GRADE = 'A' ELSE IF ( MARK >= GRADE = 'B' ELSE IF ( MARK >= GRADE = 'C' ELSE IF ( MARK >= GRADE = 'D' ELSE IF ( MARK >= GRADE = 'E' ELSE GRADE = 'F' END IF THEN 60 ) THEN 50 ) THEN 40 ) THEN 30 ) THEN

PRINT *, 'Grade is ', GRADE END DO END PROGRAM EXAM PROGRAM EXAM IMPLICIT NONE INTEGER MARK CHARACTER GRADE

DO WRITE ( *, '("Enter mark (negative to end): ")', ADVANCE = 'NO' ) READ *, MARK IF ( MARK < 0 ) STOP ! program ends if a negative value is input SELECT CASE ( MARK ) CASE ( 70: ) GRADE = 'A' CASE ( 60:69 ) GRADE = 'B' CASE ( 50:59 ) GRADE = 'C' CASE ( 40:49 ) GRADE = 'D' CASE ( 30:39 ) GRADE = 'E' CASE ( :29 ) GRADE = 'F' END SELECT PRINT *, 'Grade is ', GRADE END DO END PROGRAM EXAM

Fortran

Week 2 - 4

David Apsley

PROGRAM MATRIX IMPLICIT NONE REAL, DIMENSION(3,3) :: A, B, C REAL A(3,3), B(3,3), C(3,3) ! REAL PI INTEGER I, J CHARACTER (LEN=*), PARAMETER :: FMT ! declare size of A, B and C alternative dimension statement ! the number pi ! counters = '( A, 3(/, 3(1X, F8.3)), / )' ! format string for output

! Basic initialisation A(1,1) = 1.0; A(1,2) A(2,1) = 4.0; A(2,2) A(3,1) = 7.0; A(3,2) B(1,1) = 10.0; B(2,1) = 40.0; B(3,1) = 70.0;

of matrices = 2.0; A(1,3) = 3.0 = 5.0; A(2,3) = 6.0 = 8.0; A(3,3) = 9.0 B(1,3) = 30.0 B(2,3) = 60.0 B(3,3) = 90.0

! !

! Alternative initialisation using DATA statements DATA A / 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 / DATA B / 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 /

! Write out matrices WRITE ( *, FMT ) 'A', ( ( A(I,J), J = 1, 3 ), I = 1, 3 ) WRITE ( *, FMT ) 'B', ( ( B(I,J), J = 1, 3 ), I = 1, 3 )

! Some operation applied to all elements of a matrix PI = 4.0 * ATAN( 1.0 ) C = SIN( B * PI / 180.0 ) WRITE ( *, FMT ) 'SIN(B)', ( ( C(I,J), J = 1, 3 ), I = 1, 3 ) END PROGRAM MATRIX

Fortran

Week 2 - 5

David Apsley

- Parameter Template 3GUploaded byYunandar
- Nesoft Configuration Command Line Reference (1)Uploaded byandaihiep
- Zai 00005Uploaded byBalakrishna Vegi
- C++ Ders3 - FonksiyonlarUploaded byŞemsettin karakuş
- Functions in SQL Server Practical GuideUploaded bytbijle
- Pro-e Drawing Sys Parameter DwgUploaded byrendrapradana
- [Series in Computational Physics] David J. Pine - Introduction to Python for Science and Engineering (2019, CRC Press).pdfUploaded byShuvam Pyakurel
- Chapter-09_Overview-of-Search-Helps.pptUploaded bynivas
- MXnetUploaded byRps Deepan
- Computer Science Set 2Uploaded bynita23arora2321
- PYT String FormattingUploaded bytgs100
- plantserviceandcheckers cUploaded byapi-340729449
- VFDUploaded byVijaya Kumar
- HC900 Function BlockUploaded byKan Chora
- 14229Uploaded byulisse_
- DieQuote_Generator.pdfUploaded byovidius1ru1616
- Sap Workflow TutorialUploaded bySreenivas Kupireddy
- About an approximate formula for scattering amplitude by a discUploaded byFumihiro Chiba
- CH05 Query - Rules That Apply to Queries and to Their ResponsesUploaded byremedymd
- crank&camdescription.pdfUploaded bysamuel samir
- USR ReportsUploaded byHitesh Pathak
- Master Drive 6RA70 Parameter ListUploaded bysanjaya srivastava
- Type19 SupplementUploaded byhugo_oliveira_4
- AdoUploaded bySamrat Pv
- Stored ProcedureUploaded byNikunj Jhala
- Technical Reference Manual - RAPID Instructions, Functions and Data TypeUploaded byMarcus Hardt Filho
- AppEngine Exer 2.pdfUploaded byAnush Reddy
- BI Apps Parameters Configuration DetailsUploaded bysatyanarayana NVS
- Lesson 6Uploaded byLim C
- chapter 3- functions sir shahzadUploaded byapi-394738731

- Fractions GuideUploaded byVinay Gupta
- Comparitive Study Cav ModelsUploaded byVinay Gupta
- On the Second OrderUploaded byVinay Gupta
- Neptune LSIUploaded byVinay Gupta
- PDF Iihr444Uploaded byVinay Gupta
- Lam MasterTechWiskUploaded byVinay Gupta
- Chap4 Waves BasicsUploaded byVinay Gupta
- Introduction to Ship Hydro Mechanics Pinkster 2002)Uploaded byntontarski
- Meland Afmc 16 07Uploaded byVinay Gupta
- Fraction Animal ClassUploaded byVinay Gupta
- Pij05SVWUploaded byVinay Gupta
- Pij05SVWUploaded byVinay Gupta
- EN-AVT-143-02Uploaded byDiego1980b
- Oblique Wave Experimental REsultsUploaded byVinay Gupta
- Pij03SVUploaded byVinay Gupta
- pipe_flowUploaded byVinay Gupta
- 61 Darcy EmpUploaded byVinay Gupta
- Fluid FlowUploaded byDavid Hayes
- Flow Past a Sphere Ch3Uploaded bymheinric
- Case13Uploaded byVinay Gupta
- ITK-233-2_PVT Behavior of FluidUploaded byVinay Gupta
- GetMmoUploaded byVinay Gupta
- Lecture 4Uploaded byVinay Gupta
- Pipe Flow1Uploaded byVinay Gupta
- Lecture 5Uploaded byVinay Gupta
- 1_flow_mechUploaded byVinay Gupta
- 04-clsfn.pptUploaded byAatresh Karnam
- EulerUploaded byPejman Edalat
- Handout EqnsUploaded byNaga Seshu
- Free Surface InstabilityUploaded byVinay Gupta

- Code 1Uploaded bytripathiambrish
- Assembly Lab 2Uploaded byJefferson Medinaceli Malayao
- 46 Hibernate Interview Questions and Answers - Freshers, ExperiencedUploaded byDelli Harin
- CodeUploaded byniketmulye
- DZONE - Getting Started with Appium for Mobile TestingUploaded byjeyaganeshn
- C TestUploaded byVishnu Vandana
- dbmsUploaded byselin ravikumar
- JAVA notes gistUploaded byf_ahamedsha
- How Do i Use the Cron to Schedule a BackupUploaded byCesar Ubilla
- c++_gnuradioUploaded bynadeemp78
- Reference 1Uploaded byhimalnepali
- Eetop.cn_dIY Deep Learning for Vision- a Hands-On Tutorial With CaffeUploaded byexfmln
- C++ - 2Uploaded byGâgäñ Løhîă
- gdbUploaded byHina Jajoo
- Sl-110Uploaded byhossam_fadeel2560
- Debugger TricoreUploaded bycarver
- Server Customization Programmers GuideUploaded bykpanku
- Opencv TutorialsUploaded byt0mkaka
- 1.3.7 High- And Low-level Languages and Their TranslatorsUploaded byRana Hassan Tariq
- Ar TransactionsUploaded byreddyvijayk
- 03 JDBC MySQLUploaded byquick311
- S7-300_400 Tip Analog Scaling Tip No. 1Uploaded bymail87523
- PPLHW1Uploaded bygameloon
- C++ Problem SetUploaded byEnoch Park
- Intro to SpringUploaded bywqeruyqwioeruy
- Stored ProceduresUploaded byswaroop24x7
- Code Like a Pythonista- Idiomatic PythonUploaded bymarcelloseri
- school automation systemUploaded bymohantyramakant
- Assignment2_kavya_puligundlaUploaded bykmaheshp
- Os ProgramsUploaded byrijine