Programming in Fortran 90 : 2017/2018

Similar documents
Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search

CS1100 Introduction to Programming

Exercises (Part 4) Introduction to R UCLA/CCPR. John Fox, February 2005

CMPS 10 Introduction to Computer Science Lecture Notes

Problem Set 3 Solutions

Course Introduction. Algorithm 8/31/2017. COSC 320 Advanced Data Structures and Algorithms. COSC 320 Advanced Data Structures and Algorithms

Sorting. Sorted Original. index. index

CSCI 104 Sorting Algorithms. Mark Redekopp David Kempe

Brave New World Pseudocode Reference

Support Vector Machines

Sorting. Sorting. Why Sort? Consistent Ordering

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

Life Tables (Times) Summary. Sample StatFolio: lifetable times.sgp

An Application of the Dulmage-Mendelsohn Decomposition to Sparse Null Space Bases of Full Row Rank Matrices

Design and Analysis of Algorithms

GSLM Operations Research II Fall 13/14

Parallelism for Nested Loops with Non-uniform and Flow Dependences

Outline. Midterm Review. Declaring Variables. Main Variable Data Types. Symbolic Constants. Arithmetic Operators. Midterm Review March 24, 2014

Parallel Numerics. 1 Preconditioning & Iterative Solvers (From 2016)

The Codesign Challenge

Priority queues and heaps Professors Clark F. Olson and Carol Zander

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Sorting and Algorithm Analysis

Sorting Review. Sorting. Comparison Sorting. CSE 680 Prof. Roger Crawfis. Assumptions

Searching & Sorting. Definitions of Search and Sort. Linear Search in C++ Linear Search. Week 11. index to the item, or -1 if not found.

Parallel matrix-vector multiplication

Today s Outline. Sorting: The Big Picture. Why Sort? Selection Sort: Idea. Insertion Sort: Idea. Sorting Chapter 7 in Weiss.

Lecture 5: Multilayer Perceptrons

Sorting: The Big Picture. The steps of QuickSort. QuickSort Example. QuickSort Example. QuickSort Example. Recursive Quicksort

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

NUMERICAL SOLVING OPTIMAL CONTROL PROBLEMS BY THE METHOD OF VARIATIONS

ELEC 377 Operating Systems. Week 6 Class 3

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

X- Chart Using ANOM Approach

Computer Animation and Visualisation. Lecture 4. Rigging / Skinning

Polyhedral Compilation Foundations

Accounting for the Use of Different Length Scale Factors in x, y and z Directions

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

S1 Note. Basis functions.

Lecture #15 Lecture Notes

EVALUATION OF THE PERFORMANCES OF ARTIFICIAL BEE COLONY AND INVASIVE WEED OPTIMIZATION ALGORITHMS ON THE MODIFIED BENCHMARK FUNCTIONS

y and the total sum of

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Dijkstra s Single Source Algorithm. All-Pairs Shortest Paths. Dynamic Programming Solution. Performance. Decision Sequence.

An Optimal Algorithm for Prufer Codes *

Conditional Speculative Decimal Addition*

Mathematics 256 a course in differential equations for engineering students

Radial Basis Functions

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Problem Definitions and Evaluation Criteria for Computational Expensive Optimization

LU Decomposition Method Jamie Trahan, Autar Kaw, Kevin Martin University of South Florida United States of America

The Greedy Method. Outline and Reading. Change Money Problem. Greedy Algorithms. Applications of the Greedy Strategy. The Greedy Method Technique

Module Management Tool in Software Development Organizations

Dijkstra s Single Source Algorithm. All-Pairs Shortest Paths. Dynamic Programming Solution. Performance

UNIT 2 : INEQUALITIES AND CONVEX SETS

Insertion Sort. Divide and Conquer Sorting. Divide and Conquer. Mergesort. Mergesort Example. Auxiliary Array

Virtual Memory. Background. No. 10. Virtual Memory: concept. Logical Memory Space (review) Demand Paging(1) Virtual Memory

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements

ON SOME ENTERTAINING APPLICATIONS OF THE CONCEPT OF SET IN COMPUTER SCIENCE COURSE

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface.

A Facet Generation Procedure. for solving 0/1 integer programs

Programming Assignment Six. Semester Calendar. 1D Excel Worksheet Arrays. Review VBA Arrays from Excel. Programming Assignment Six May 2, 2017

Greedy Technique - Definition

9. BASIC programming: Control and Repetition

NAG Fortran Library Chapter Introduction. G10 Smoothing in Statistics

On Some Entertaining Applications of the Concept of Set in Computer Science Course

Reading. 14. Subdivision curves. Recommended:

CHAPTER 10: ALGORITHM DESIGN TECHNIQUES

CS240: Programming in C. Lecture 12: Polymorphic Sorting

Analysis of Continuous Beams in General

Outline. Self-Organizing Maps (SOM) US Hebbian Learning, Cntd. The learning rule is Hebbian like:

U.C. Berkeley CS294: Beyond Worst-Case Analysis Handout 5 Luca Trevisan September 7, 2017

Esc101 Lecture 1 st April, 2008 Generating Permutation

11. APPROXIMATION ALGORITHMS

Kinematics of pantograph masts

ROBOT KINEMATICS. ME Robotics ME Robotics

Array transposition in CUDA shared memory

A SYSTOLIC APPROACH TO LOOP PARTITIONING AND MAPPING INTO FIXED SIZE DISTRIBUTED MEMORY ARCHITECTURES

An Iterative Solution Approach to Process Plant Layout using Mixed Integer Optimisation


Machine Learning: Algorithms and Applications

Kent State University CS 4/ Design and Analysis of Algorithms. Dept. of Math & Computer Science LECT-16. Dynamic Programming

AMath 483/583 Lecture 21 May 13, Notes: Notes: Jacobi iteration. Notes: Jacobi with OpenMP coarse grain

OPL: a modelling language

LOOP ANALYSIS. The second systematic technique to determine all currents and voltages in a circuit

CE 221 Data Structures and Algorithms

7/12/2016. GROUP ANALYSIS Martin M. Monti UCLA Psychology AGGREGATING MULTIPLE SUBJECTS VARIANCE AT THE GROUP LEVEL

Computer models of motion: Iterative calculations

Today Using Fourier-Motzkin elimination for code generation Using Fourier-Motzkin elimination for determining schedule constraints

News. Recap: While Loop Example. Reading. Recap: Do Loop Example. Recap: For Loop Example

Quadruple Precision Eigenvalue Calculation Library. QPEigen Ver.1.0

Storage Binding in RTL synthesis

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

Vectorization in the Polyhedral Model

Solutions to Programming Assignment Five Interpolation and Numerical Differentiation

Introduction to Geometrical Optics - a 2D ray tracing Excel model for spherical mirrors - Part 2

Intro. Iterators. 1. Access

Outline. Third Programming Project Two-Dimensional Arrays. Files You Can Download. Exercise 8 Linear Regression. General Regression

Transcription:

Programmng n Fortran 90 : 2017/2018 Programmng n Fortran 90 : 2017/2018 Exercse 1 : Evaluaton of functon dependng on nput Wrte a program who evaluate the functon f (x,y) for any two user specfed values x and y, where the functon f (x,y) s defned as follows : x + y f x 0 and y 0 x + y f (x,y) = 2 f x 0 and y < 0 x 2 + y f x < 0 and y 0 x 2 + y 2 f x < 0 and y < 0 Exercse 2 : Crcle and Sphere Wrte a program that read the radus of a crcle at the prompt et gve the area and volume of the correspondng crcle and sphere (πr 2 and 4/3πr 3 ). Exercse 3 : System soluton Wrte a program whch resolve the folowng system of 2 equatons wth 2 unknows x and y : a 1 x + b 1 y = c 1 a 2 x + b 2 y = c 2 Exercse 4 : Do loops What are the teraton counts of the followng DO loops, the values of the loop varable nsde the loop, and the value of the loop varable after the DO construct? do = 1, 5 do = 5, 0, -1 do = 10, 1, -2 do = 0, 30, 7 do = 3, 2, 1 Wrte a program prntng nsde and outsde the loop to verfy your results. Exercse 5 : Temperature converson Wrte a program n a do loop whch gves a Celsus (T c ) to Fahrenhet (T f ) converson table n unts steps from 50 to 50 Celsus. The converson formula s : T c = 5 9 (T f 32) 1

Programmng n Fortran 90 : 2017/2018 Exercse 6 : Seres Wrte a program whch read an nteger value n, then compute and wrte on the screen the n frst terms of the seres u n+1 = 2u n + 3, wth u 0 = 1. Same queston for the Fbonacc seres u n+1 = u n + u n 1, wth u 0 = u 1 = 1. Exercse 7 : π computaton Formula 1 : Wrte a program whch compute π wth followng formula : π/4 = arctan(1) = n= n=0 ( 1) n /(2n + 1) Fnd the number of teratons needed to obtan the followng precson : 3.1415926535897 Formula 2 : Do the same wth ths formula wth : π/4 = 4 arctan(1/5) arctan(1/239) arctan(x) = n= n=0 ( 1) n x2n+1 2n + 1 and compare the number of teratons of the two formulas for the same precson. Exercse 8 : Quadratc equaton solver Wrte a program to calculate the roots of a quadratc equatons of the form ax 2 + bx + c = 0 The algorthm : Read a, b and c. Check that a 0. If a = 0, the equaton s lnear. Compute the soluton. Prnt the soluton. 2

Programmng n Fortran 90 : 2017/2018 Test your program for each case : one root, two real roots, two complex roots. Hnt : The program has a sngle root f b 2 4ac = 0 two real roots f and magnary roots f b 2 4ac > 0 b 2 4ac < 0 Exercse 9 : Arrays Gven the followng declaratons: real(4), dmenson(1:10,1:20) :: a real(4), dmenson(10,-5:10) :: b real(4), dmenson(0:5,1:3,6:9) :: c real(4), dmenson(1:10,2:15) :: d What s the rank, sze, bounds, and extents of a,b,c and d? Gven the followng declaratons: real(4), dmenson(-1:5,3,8) :: alpha real(4), dmenson(-3:3,0:2,-7:0) :: beta Are the two arrays conformable? Gven the followng array declaraton real(4): a(0:5,3) whch of the followng references are legal? a(2,3), a(6,2), a(0,3), a(5,6), a(0,0) What s the array element order of the followng array? nteger, dmenson(-1:1,2,0:1) :: alpha The followng array declaratons are gven: real(4), dmenson(50) :: alpha real(4), dmenson(60) :: beta whch of the followng statements are vald? 3

Programmng n Fortran 90 : 2017/2018 alpha=beta alpha(3:32)=beta(1:60:2) alpha(10:50)=beta alpha(10:49)=beta(20:59) alpha=beta(10:59) alpha(1:50:2)=beta beta=alpha beta(1:50)=alpha Exercse 10 : Selecton sortng Sortng a lst s a classcal algorthm. Several methods exsts, some are more effcent than others. The algorthm works as follows: Fnd the mnmum value n the lst Swap t wth the value n the frst poston Repeat the steps above for the remander of the lst (startng at the second poston and advancng each tme) 4

Programmng n Fortran 90 : 2017/2018 mn 18 3 10 25 3 18 10 25 9 3 11 13 23 8 mn 9 3 11 13 23 8 mn 3 3 10 25 9 18 11 13 23 8 mn 3 3 8 25 9 18 11 13 23 10 mn 3 3 8 9 25 18 11 13 23 10 mn 3 3 8 9 10 18 11 13 23 25 mn 3 3 8 9 10 11 18 13 23 25 mn 3 3 8 9 10 11 13 18 23 25 mn 3 3 8 9 10 11 13 18 23 25 18 3 10 25 9 3 11 13 23 8 Wrte a program that create (wth the random_number ntrnsc subroutne) an 1D-array contanng nteger between 0 and 10, sort ths array wth the selecton sortng algorthm and wrte the sorted result on the screen. Exercse 11 : Smple example of a Subroutne Wrte a subroutne wth three parameters, two real numbers a and b as nput and a real number c as output. The subroutne should return c as the sum of a and b. Wrte the program callng the subroutne. Exercse 12 : Smple example of a Functon Wrte a functon wth two parameters, two real numbers a and b. The functon should return c as the sum of a and b. Wrte the program callng the functon. 5

Programmng n Fortran 90 : 2017/2018 Exercse 13 : Smple Statstcs Wrte a man program and ths two functons : functon 1 : returns the mean of a sequence of values (x, = 1,n) : m = 1 n n x =1 functon 2 : returns the varance of a sequence of values (x, = 1,n) usng the frst functon to compute the mean. v = 1 n n =1 (x m) 2 Use the random_number ntrnsc subroutne to create the sequence of values. Exercse 14 : Bubble sortng Bubble sort s a smple sortng algorthm that works by repeatedly steppng through the lst to be sorted, comparng each par of adjacent tems and swappng them f they are n the wrong order. The pass through the lst s repeated untl no swaps are needed, whch ndcates that the lst s sorted. The algorthm gets ts name from the way smaller elements "bubble" to the top of the lst. Because t only uses comparsons to operate on elements, t s a comparson sort. Wrte a subroutne bubble_sort(...) wth the array you want to sort and the number of elements as nput. The array should be sorted when you leave the subroutne. Wrte a man program wch create the array and fll t wth the random_number ntrnsc subroutne and sort t wth the bubble_sort(...) subroutne and wrte the sorted result n a fle. Exercse 15 : Sequental search Lnear search or sequental search s a method for fndng a partcular value n a lst, that conssts of checkng every one of ts elements, one at a tme and n sequence, untl the desred one s found. Wrte a subroutne whch mplement ths algorthm. The nputs should be the lst and t length, the outputs beng the answer (yes or no the elements s n the lst) and f the element s n the lst, the poston n the lst. If the element s present more than one tme, only the frst element wll be reported. The man program wll have to read the lst from a fle and output the results. Gve also the number of comparsons needed proportonally to the number of elements of the lst, n order to have an estmate of the effcency of the algorthm. Exercse 16 : Dchotomc search A dchotomc search s a search algorthm that operates by selectng between two dstnct alternatves (dchotomes) at each step. Here, we wll explot the fact that the lst has been already sorted (wth one of the algorthm already done). The frst step s to compare the mddle element of the lst wth the key element. If t s the same, we have found t and we can stop. If not, we repeat ths operaton on half of the lst, dependng f the key element s greater or lower than the mddle element. 6

Programmng n Fortran 90 : 2017/2018 Wrte a subroutne whch mplement the algorthm. Gve also the number of comparsons needed proportonally to the number of elements of the lst, n order to have an estmate of the effcency of the algorthm and compare t wth the sequental search. Exercse 17 : Matrx transpose A s a square matrx of real numbers of sze N N. Wrte a subroutne verb transmat whch takes as arguments N and A. The matrx A has to be transposed when gong out of the subroutne. The only array used n verb transmat should be A. Wrte a subroutne read_matrx that read a matrx from a fle and a subroutne wrte_matrx that wrte the result n another fle. Wrte the man program usng the three subroutnes. The fles should be formatted ths way : a 11 a 21 a 31... a 12 a 22 a 32......... Exercse 18 : Matrx multplcaton Wrte a subroutne perfomng the matrx multplcaton of two matrx A of sze (m,n) and B of sze (n, p). The subroutne should return the resultng matrx C of sze (m, p). Wrte a subroutne read_matrx that read a matrx from a fle and a subroutne wrte_matrx that wrte the result n another fle. Wrte the man program usng the three subroutnes. The fles should be formatted n the same format that the prevous exercse. 7