Information about PHYS303

PHYS303

SUBPROGRAMS • Fortran codes that solve real problems often have tens of thousands of lines. • The only way to handle such big codes is to split them into many smaller subprograms. • Subprogram is a small piece of code that solves a speciﬁc well deﬁned subproblem. • subprogram can be invoked several times for different inputs during the calculations. • Fortran has two different types of subprograms: Functions and subroutines. • we start the subprograms by typing contains. 2/7

F UNCTIONS • Similar to mathematical functions, Fortran functions takes a set of input variables or parameters and return a output values. • In general, Fortran function always has a type, .i.e, real, integer etc. • The returns values has to be stored in a variable has the same name of the function. • Functions are terminated by return statement instead of stop. • Variables deﬁned inside Function are invisible by the main body • A function can call another function • Only one function for each function subprogram • General structure of a function is: type function name (variables) declarations statements return 3/7

E XAMPLES ON F UNCTIONS program myfunction implicit none real q,r read*,q,r print*,f(q),g(q,r) !---------------------contains real function f(x) real:: x f=2.0-x-x**2 return end function !---------------------real function g(x,y) real:: x,y,t t=f(x) g=x*y-y**2+f(x) !or g=x**2+xy**3+t-t**2/(1-t)+t**4/(1-t)**3 return end function end program myfunction !---------------------- 4/7

S UBROUTINE • The subroutine has no type. • The body of subroutine is actually a small program and could return more than one value • General structure of a subroutine is: subroutine name (input variables,output variables) declarations statements return end 5/7

E XAMPLES ON SUBROUTINE program summations implicit none real q,r,w read*,q call summ(q,r,w) print*,r,w !---------------------contains subroutine summ(x,y,z) implicit none real, intent(in)::x real,intent(out)::y,z integer i; real phi phi=0 do i=1,10 phi=phi+x*(i) enddo y=sqrt(phi) z=sin(y) end subroutine summ end program 6/7

C ONT.. program swaping implicit none real i,j read*,i,j print’(1x,a,I2,5x,a,I2)’,"i=",i,"j=",j call swap(i,j) print’(1x,a,I2,5x,a,I2)’,"i=",i,"j=",j !---------------------contains subroutine swap(m,n) implicit none real, intent(inout)::m,n real phi phi=m m=n n=phi end subroutine swap end program 7/7

Course description: ( عربي ) PHYS303 is the first semester of an undergraduate two-semester sequence of electromagnetic theory which covers the basic ...

Read more

Atomic and Solid-State Physics - PHYS303. ... Macquarie University, Sydney | Last Updated: Thursday, 15th October, 2015 . ABN 90 952 ...

Read more

PHYS 303: Classical Mechanics (Fall 2015) Syllabus. Course Materials

Read more

Contents AdvancedMechanicsII.Phys303 1 Lecture1.ReviewofPhys302. Newtonianformulation. 1 1.1. Conservationlaws. 1 Lecture2.ReviewofPhys302 ...

Read more

Classical Mechanics — Physics 303 Fall Semester 2013 Also available at http://physics.wm.edu/~carlson/phys303.pdf For 2012 ﬁnal exam, go to http ...

Read more

Professor: Keith Griffioen Office: Small 215 Phone: 1-3537 Office Hours: by appointment Lectures: MWF 10am; Small 102 Problem Session: F 2pm; Small 102

Read more

classical mechnics fall 2013 ... schedule (including lecture notes, HW assignments and HW solutions) grading: The grades will be an average of homework ...

Read more

Syllabus - Fall 2012 Physics 303 – Classical Mechanics Robert N. Oerter (roerter@gmu.edu) Office Hours: MWF 9:30-10:20 AM Room 301B, Science & Tech I ...

Read more

Mathematica (2) Mathematica can be used to find symbolic or numerical values of derivatives of functions. To evaluate the derivative of f(x) = a xn we can ...

Read more

- 2 - It is hard to tell from this plot where the minima are, but if one follows the contour lines and colors it looks like there might be a minimum at ...

Read more

## Add a comment