logo

Fortran Programs Code

6 Pages1119 Words84 Views
   

Added on  2022-12-23

About This Document

This document contains Fortran programs code to find the derivatives of sin(x) at point x=1. It also includes a Fortran program to use Simpson's rule to evaluate an integral.

Fortran Programs Code

   Added on 2022-12-23

ShareRelated Documents
Running head: FOTRAN CODE 1
Fotran Programs Code
Name
Institution
Fortran Programs Code_1
FOTRAN CODE 2
Fotran Programs Code
Write a program to find the derivatives of sin (x) at point x=1 (given in
radians)
Program Part 1
Program Deriv
implicit none
integer ::n,i
real, allocatable :: y(:) dydx(:)
real ::x dx
write(*, ‘(a,$)’) ‘input number of grid points:’ ; read*, n
allocate (y(n), dydx(n)) ! allocate grid arrays
dx = 10.0/(n-1) !grid spacing, assuming x from 0 -10
do i= 1,n
x= (i-1)
y(i) =sin (x) !fill with sine
end do
cal derivative (y, n, dx, dydx) ! calculate dydx
do i= 1, n ! write result, cos(x) and error
x= (i-1) *dx
print*, dydx(i), cos(x), cosx-dydx(i)
end do
deallocate (y, dydx) !finish
contains
sunroutine derivative (a, np, h, aprime) ! argument names different
integer, intent (in) :: np !declare argument
real, intent(in) :: a(np), h
real, intent(out):: aprime (np)
integer :: i local variable
do i=1, np=1
aprime(i)= (a(i+1)- a (i))/h !finite-defference formula
end do
Fortran Programs Code_2
FOTRAN CODE 3
aprime(np) = 0
end subroutine derivative
end program Deriv
Write a FORTRAN program to use Simpson's rule to evaluate the integral given by
where,, and Indicate in the comment block (at the beginning of your code) what value you
obtained for the integral as a function of the number of subintervals used. Make sure to
clearly indicate what you think is the most accurate value for the integral.
Submit the source code file, i.e. the .f08 file containing the Fortran code, by uploading it
into blackboard using the “attachments” button under the assignment. If you have any
problems see the TA or the instructor. Submissions via email will not be accepted.
Note:
All programs must contain the implicit none statement. Programs that do not contain
this statement will receive an automatic zero.
All programs should have a block of comment statements at the beginning of the code
containing your name and a description of what the code does.
All programs must compile using the gfortran compiler on the Math lab machines.
Programs that do not compile will receive an automatic zero.
Programs must be uploaded into the blackboard assignment page. Programs may not
be submitted via email or hardcopy. Programs that are not uploaded into the blackboard
assignment page will not be graded.
Program part 2
Simpsons solition
program integration
! declaring the variable values
real results,simp13_res,simp38_res,a,b,error
real f
integer n
Fortran Programs Code_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Automatic Differentiation (A.D.)
|16
|4143
|87