代写 algorithm Introduction to Fotran Programming (1/22) Excercise

Introduction to Fotran Programming (1/22) Excercise
Download the assignment and work on each exercise. After completing the answers, you will be asked to submit the part-15 exercises “Upload Programs” folder on “CourseN@vi” class page.
(Even if you are absent on Jan 15-22, please upload) Upload deadline: 2019/01/31 (11:59:59 pm)
Evaluate will be a total of 50 points.
I will focus on evaluating whether you can correctly use the Fortran statements you used in previous exercises.
( Doesn’t take the attendance ) The exercise is posted on the “Cource N@vi” website.

Exercise 1
Create a program with the following specification and consider the rounding error of the result.
(Program file name is “a15_1_main.f90”)
Specification:
1) Define an integer type variable “n” and assign “100”.
2) Define single precision real type variable “r1” and assign 1.0. 3) Define single precision real type variable “r2” and assign
“r1 / n”.
4) Add “r2” n times using “Do” loop.
Also, make the same calculation with “n = 1024“.

Exercise 2
Create a module and define a structure “t_fraction” with integer type members numerator and denominator. (File name: “a15_mod_fraction.f90” )
Create the following calculation function of t_fraction type in the module.
・Addition functions : frac_plus_frac, ・Subtraction functions : frac_minus_frac, ・Multiplication functions: frac_mult_frac, ・Division functions : frac_divi_frac,
Also define the “interface operator” statement.
Also, create a function “fracset” that sets an integer to a variable of t_fraction type, and a subroutine “dispfrac” to display.
In addition, add a subroutine “euclidean” that performs Eucledean algorithm, and use it in each function as necessary.
Specification of main program is same asExercise 1. However, modify the variables “r1” and “r2” as “t_fraction” type. (File name: “a15_2_main.f90” )
frac_plus_int, frac_minus_int,
frac_mult_int, frac_divi_int,
int_plus_frac int_minus_frac
int_mult_frac int_divi_frac

Exercise 3
Using the module created in Exercise 2, create a program that solves simultaneous linear equations with Gaussian elimination (fractional calculation).
(File name : a15_3_main.f90 ,
・・・
implicit none real::A(3,3),b(3) real::x(3)
A(1,:)=(/3.0, 2.0, 1.0/) A(2,:)=(/2.0, 3.0, 1.0/) A(3,:)=(/1.0, 2.0, 3.0/) b(:)=(/39.0,34.0,26.0/)
call gaussian(A,b,3,x)
・・・
a15_3_gaussian.f90 )
subroutine gaussian(a,b,n,x)
implicit none
integer,intent(in):: n real,intent(in):: a(n,n), b(n) real,intent(out):: x(n) type(t_fraction),allocatable:: Ab(:,:)
・・・
Ab(i, j) = fracset( INT( a(i,j) ) )
・・・
Ab(i,j)= Ab(i,j) – Ab(k,j) * Ab(i,k)
・・・

a15_3_main.f90
program matrix_33 implicit none
real:: a(3,3),b(3),x(3)
! Input data
a(1,1)=3; a(1,2)=2; a(1,3)=1 a(2,1)=2; a(2,2)=3; a(2,3)=1 a(3,1)=1; a(3,2)=2; a(3,3)=3 b(1)=39; b(2)=34; b(3)=26
call gaussian(a,b,3,x)
write(*,*) ‘x=’,x(1),x(2),x(3) stop
end program matrix_33
Exercise 3 execute example (P1)
参考: Real変数での同一計算例 Reference information :
Same calculation example with Real variable
[ito@localhost ~]$ gfortran a15_mod_fraction.f90 a15_3_gaussian.f90 a15_3_main.f90
[ito@localhost ~]$ ./a.out
–step 1–
3/1 2/1 1/1 39/1 2/1 3/1 1/1 34/1 1/1 2/1 3/1 26/1
–step 3–
1/1 2/3 1/3 39/3 0/1 5/3 1/3 24/3 1/1 2/1 3/1 26/1 –step 3–
1/1 2/3 1/3 39/3 0/1 5/3 1/3 24/3 0/1 4/3 8/3 39/3
・・・・
–step 2,3–
1/1 2/3 1/3 39/3 0/1 1/1 3/15 72/15 0/1 0/1 1/1 11/4 –step 7,8,9–
1/1 2/3 1/3 39/3 0/1 1/1 3/15 72/15 0/1 0/1 1/1 11/4
f: 37/4 f: 17/4 f: 11/4
x= 9.25000000 4.25000000 2.75000000
–step 1–
3.0000 2.0000 1.0000 39.0000 2.0000 3.0000 1.0000 34.0000 1.0000 2.0000 3.0000 26.0000
–step 3–
1.0000 0.6667 0.3333 13.0000 0.0000 1.6667 0.3333 8.0000 1.0000 2.0000 3.0000 26.0000
–step 3–
1.0000 0.6667 0.3333 13.0000 0.0000 1.6667 0.3333 8.0000 0.0000 1.3333 2.6667 13.0000
・・・・
–step 2,3–
1.0000 0.6667 0.3333 13.0000 0.0000 1.0000 0.2000 4.8000 0.0000 0.0000 1.0000 2.7500
–step 7,8,9–
1.0000 0.6667 0.3333 13.0000 0.0000 1.0000 0.2000 4.8000 0.0000 0.0000 1.0000 2.7500
x(1)= 9.24999905 x(2)= 4.25000048 x(3)= 2.74999976

Exercise 4
Declare an integer type variable for “n”, “r” so that positive values can be read with read statements.
Create a recursive call function “combi” to calculate combination
nCr
Make the file name “a15_4_combi.f90”.
Hint: nCr=n-1Cr+n-1Cr-1