Programming Example Report 14
program report14
implicit none
real(8)::t,k
real,parameter::TOL=1.0D-6
real(8),dimension(5)::NPV,s
integer::i
s(1)=0.0;s(2)=10.0;s(3)=15.0;s(4)=20.0;s(5)=25.0
do i=1,5
NPV(i)=forming(s(i))
End do
k=0.0
do while(forming(k)>=0)
k=k+TOL
enddo
write(*,'(T5,A,$)') "Rates of interest(%)"
write(*,'(T10,A)') "Net present values($)"
write(*,'(A)') repeat("=",55)
do i=1,5
write(*,'(T12,f5.2,T37,I10)') s(i),nint(NPV(i))
end do
write(*,'(A)') repeat("=",55)
write(*,'(A,F10.4,A)') "The internal rate of return is ", k,"%"
open(1,file="NPV.txt")
write(1,'(T5,A,$)') "Rates of interest(%)"
write(1,'(T10,A)') "Net present values($)"
write(1,'(A)') repeat("=",55)
do i=1,5
write(1,'(T12,f5.2,T37,I10)') s(i),nint(NPV(i))
end do
write(1,'(A)') repeat("=",55)
write(1,'(A,F10.4,A)') "The internal rate of return is ", k,"%"
close(1)
contains
function forming(t)
real(8)::forming,t,x
integer::i
x=t/100
forming=-300000+150000/(1+x)+150000/(1+x)**2+160000/(1+x)**3
end function forming
end program report14
! Result
! Rates of interest(%) Net present values($)
! =======================================================
! 0.00 160000
! 10.00 80541
! 15.00 49059
! 20.00 21759
! 25.00 -2080
! ============================================================
! The internal rate of return is 24.5366%
Programming Example 13
Program Least_squares
implicit none
! Global variables
integer, parameter:: m=4 ! Number of coefficient
real(8):: S(m) ! Array of coefficient S
real(8), parameter:: TOL=1D-6 ! Numerical tolerance
real(8), dimension(:), allocatable:: X, Y ! Arrays of data X and Y
Call Initialization(X, Y, S) ! read data from file
Call Processing(X, Y, S) ! perform numerical analysis and display
Call Finalization(X, Y, S) ! write data to file
contains
!================================================================================
Subroutine Initialization(X, Y, S)
! dummy variables
real(8), dimension(:), allocatable, INTENT(OUT):: X, Y
real(8), INTENT(OUT):: S(m)
! local variables
integer:: i, n, status=0
character(len=50):: filename
real(8):: r
write(*,'(A)') "Enter the title of input data with the file extension"
read(*,*) filename
open(1, file=filename)
n=0
do
read(1, *, iostat=status) r
if (status/=0) exit
n=n+1
end do
allocate(X(n), Y(n))
rewind(1)
do i=1,n
read(1, *) X(i), Y(i)
end do
close(1)
write(*,'(A)') "The input data"
write(*,'(2A10)') "Data X", "Data Y"
do i=1,n
write(*,'(2F10.3)') X(i), Y(i)
end do
write(*,*) "The fitting function is Y = exp(-S1*X)*sin(S2*X)*S3+S4"
write(*,*) "In order to determine non-trivial fitting coefficients, intialial values are necessary."
do i = 1, m
write(*, '(A, I1, A, $)') "Input the guessed value for S", i, " = "
Read(*,*) S(i)
end do
end subroutine Initialization
!================================================================================
Subroutine Processing(X, Y, S)
! dummy variables
real(8), dimension(:), INTENT(IN):: X, Y
real(8), INTENT(INOUT):: S(m)
! local variables
integer:: i, k, k_max=50 ! iteration number and maximum iteration number
! Norm of errors, vector residuals and Hessian matrix
real(8):: err, R(m), H(m,m)
write(*, '(A)') repeat('-',10*m+30)
write(*,'(A10, $)') "Iteration"
do i=1, m
write(*,'(A9, I1, $)') "S", i
end do
write(*,'(A20)') "Norm of residuals"
write(*, '(A)') repeat('-',10*m+30)
R=Residual_vector(X, Y, S)
err=sqrt(dot_product(R,R))
k=0
write(*,'(I10, $)') k
do i=1, m
write(*,'(F10.3, $)') S(i)
end do
write(*,'(E20.3)') ERR
do while *1
k=k + 1
H=Hessian_matrix(X, Y, S) !This caluclates the Hessian wrt X,Y,S
S=S-matmul(Minverse(H),R) !This remakes S. S=S- [Hessian]**(-1) × RessidualMatrix
R=Residual_vector(X, Y, S) !Remakes R with new S.
err=sqrt(dot_product(R,R)) !Remakes ERR with new ResidualVector
write(*,'(I10, $)') k
do i=1, m
write(*,'(F10.3, $)') S(i)
end do
write(*,'(E20.3)') ERR
end do
if (k==k_max) then
write(*,*) "Divergence!"; STOP
end if
write(*, '(A)') repeat('-',10*m+30)
end Subroutine Processing
!================================================================================
Subroutine Finalization(X, Y, S)
! dummy variables
real(8), dimension(:), INTENT(IN):: X, Y
real(8), INTENT(IN):: S(m)
! local variables
Integer:: i, n
character(len=50):: filename
n=size(X) ! rows of vector X
write(*,'(A)') "Enter the title of output data with the file extension"
read(*,*) filename
open(2, file=filename)
write(*,'(A)') "The output data"
write(*,'(2A10)') "Data X", "Fitting Y"
do i=1,n
write(*,'(2F10.3)') X(i), Fit(X(i),S)
write(2,'(2F10.3)') X(i), Fit(X(i),S)
end do
write(*, '(A, F10.3)') "Sum square of errors of the converged result is ", SSE(X, Y, S)
write(*,'(A, A, $)') "The output data have been successfully written to the file ", filename
close(2)
end Subroutine Finalization
!--------------------------------------------------------------------------------
Function SSE(X, Y, C) ! Sum Square Errors
real(8), dimension(:):: X, Y
real(8):: SSE, C(m) ! sum square of residual and coefficient array
integer:: i, n
n = size(X) ! The size of array X
SSE = 0
do i = 1, n
SSE = SSE + ( fit(X(i),C) - Y(i) )**2
end do
end Function SSE
!--------------------------------------------------------------------------------
Function Fit(z, C)
real(8):: Fit, z, C(m)
Fit = exp(-C(1)*z)*sin(C(2)*z)*C(3)+C(4)
end Function Fit
!--------------------------------------------------------------------------------
Function Residual_vector(X, Y, C)
real(8), dimension(:):: X, Y
real(8):: Residual_vector(m), C(m), C_(m)
integer:: i
do i = 1, m
C_ = C; C_(i) = C(i) + TOL
Residual_vector(i) = ( SSE(X, Y, C_) - SSE(X, Y, C) ) / TOL
end do
end Function Residual_vector
!--------------------------------------------------------------------------------
Function Hessian_matrix(X, Y, C)
real(8), dimension(:):: X, Y
real(8):: Hessian_matrix(m,m), C(m), C_(m), v(m), v_(m)
integer:: i,j
do i = 1, m
do j = 1, m
C_ = C; C_(j) = C(j) + TOL
v_ = Residual_vector(X, Y, C_)
v = Residual_vector(X, Y, C)
Hessian_matrix(i,j) = ( v_(i) - v(i) ) / TOL
end do
end do
end Function Hessian_matrix
!--------------------------------------------------------------------------------
Function Minverse(A)
real(8), dimension(:,:):: A ! Allow both static/dynamic memory allocation
real(8), dimension(:,:), allocatable:: Minverse, B, V
real(8), dimension(:), allocatable:: temp
real(8), parameter:: TOL=1D-6
real(8):: pivot
integer:: i, j, jmax, k, n
n=size(A)**0.5
allocate(Minverse(n,n), B(n,n), V(n,n), temp(n))
B=A
V(:,:)=0.
do i=1, n; V(i,i)=1.; end do
do i=1, n
jmax=i
!===== Maximum pivoting technique =====
do j=i+1, n
if (abs(B(j,i))>abs(B(jmax,i))) then
jmax=j
temp=B(i,:); B(i,:)=B(jmax,:); B(jmax,:)=temp
temp=V(i,:); V(i,:)=V(jmax,:); V(jmax,:)=temp
end if
end do
!===== Gauss-Jordan elimination =====
pivot=B(i,i)
if (abs(pivot)<TOL) then
print *, "The matrix is singular!"
stop
end if
B(i,:)=B(i,:)/pivot; V(i,:)=V(i,:)/pivot
do k=1, n
pivot=B(k,i)
if (k/=i) then
B(k,:)=B(k,:)-pivot*B(i,:)
V(k,:)=V(k,:)-pivot*V(i,:)
end if
end do
end do
Minverse=V
end function Minverse
End Program
*1:err>TOL).and.(k<k_max
Programming Example 12 日本語解説版(未完)
Program nonlinear_system
! Global variables
integer, parameter:: m=3 ! Maximum number of variables
real(8):: S(m), H(m,m) ! Unknown variable vector S
real(8), parameter:: TOL=1D-6 ! Numerical tolerance
Call Guess(S)
Call Solve(S)
contains
Function Residual(x) !ここでは計算したい方程式を設定します。
real(8):: Residual(m), x(m)
Residual(1)=-x(1)+2*x(2)+x(3)-2
Residual(2)=2*( (x(1)+3)**2) + 5*x(2)**2- (x(3)+1)**2
Residual(3)=(x(1)-5)*(x(2)+2) + 3
!以降、Residual(x)を使ったときはその時点でのx(1),x(2),x(3)が
!それぞれ代入されて、新しいResiudal(1),(2),(3)が作られます。
!目標はこの方程式を解くこと。つまり、Residual=0になるx(1),(2),(3)を
!見つけることです。以降の操作で少しづつResidualは0に近づくはずです。
end Function Residual
Function Hessian(x) !ここでは偏微分を計算します。
real(8):: Hessian(m,m), x(m), x_(m), v(m), v_(m)
integer:: i,j
do i = 1, m
do j = 1, m
x_=x
x_(j) = x(j) + TOL ! 1
v_ = Residual(x_) ! 2
v = Residual(x) ! 3
Hessian(i,j) = ( v_(i) - v(i) ) / TOL ! 4
!ここに書かれていることはいたってシンプルで簡単。
!f' = (f(x+TOL)-f(x))/TOL を計算するだけ
!1. x_(1)~x_(3)はx(1)~x(3)に1D-6を足す。
!2. それぞれResidualに入れる。
!3. vとv_を作る
!4. (v_(i)-v(i))/TOL = 微分結果
! 上の微分結果をHessian行列に格納。
end do
end do
end Function Hessian
Subroutine Guess(x) !ここはインプットを行うセクション。
real(8), INTENT(OUT):: x(m) ! dummy variables
Integer:: i
Write(*,*) "Nonlinear system of", m, "equations"
do i = 1, m
write(*, '(A, I2, A)', advance="no") "Input the guessed value no.", i, " = "
Read(*,*) x(i)
end do
! 繰り返し作業において、初期値は自分で用意しなきゃいけないので、ここで
! x(1)~(3)の初期値を読み込みます。
End Subroutine Guess
Subroutine Solve(x) !ここはコアの計算部分
real(8), INTENT(INOUT):: x(m) ! dummy variables
Integer, parameter:: k_max=50 ! Maximum iteration number
Integer:: k, n
real(8):: err, R(m), H(m,m),Minv(m,m)
!ここはディスプレイに文字を表示するだけのゾーン。
write(*,'(A10, $)') "Iteration"
do i=1, m
write(*,'(A9, I1,$)') "x", i
end do
write(*,'(A20)') "Norm of errors"
write(*, '(A)') repeat('-',60)
!ここからが大事なゾーン
!ここは最初の作業。一項目をループ外に行ってるだけ。
!もちろん後のループの中にも同じ内容があります。
R = Residual(x) !一項目を最初の方程式に入れ、Rに代入。
err=sqrt(dot_product(R,R))
k=0
write(*,'(I10, $)') k
do i=1, m
write(*,'(F10.3, $)') x(i)
end do
write(*,'(E20.3)') ERR
do while ( (err>TOL).and.(k<k_max))
k= k + 1 !カウンター
H=Hessian(x) !1. Get Hessian matrix as H using Hessian Function
Minv=Minverse(H) !2. Get inverse of Hessian matrix using Minverse Function
x=x-matmul(Minv,R) !3. Update x
R = Residual(x) !4. Set Residual matrix as R again.
err=sqrt(dot_product(R,R)) !5.Set error.
write(*,'(I10, $)') k !6. あとは書くだけ
do i=1, m
write(*,'(F10.3, $)') x(i)
end do
write(*,'(E20.3)') err
end do
if (k==k_max) then
print*, "Divergence!";stop
end if
write(*, '(A)') repeat('-',60)
End Subroutine Solve
function Minverse(A)
real(8), dimension(:,:):: A
real(8), dimension(:,:), allocatable:: Minverse, B, V
real(8), dimension(:), allocatable:: temp
real(8), parameter:: TOL=1D-6
real(8):: pivot
integer:: i, j, jmax, k, n,l
n=size(A)**0.5
allocate(Minverse(n,n),B(n,n),V(n,n),temp(n))
B=A
V(:,:)=0.0
do i=1, n
V(i,i)=1.0
end do
do i=1, n
jmax=i
do j=i+1, n
if (abs(B(j,i))>abs(B(jmax,i))) then
jmax=j
temp=B(i,:);B(i,:)=B(jmax,:);B(jmax,:)=temp
temp=V(i,:);V(i,:)=V(jmax,:);V(jmax,:)=temp
end if
end do
pivot=B(i,i)
if (abs(pivot)<TOL) then
print *, "The matrix is singular!"
end if
B(i,:)=B(i,:)/pivot
V(i,:)=V(i,:)/pivot
do k =1,n
if (i .ne. k) then
pivot=B(k,i)
do l=1,n
B(k,l)=B(k,l)-B(i,l)*pivot
V(k,l)=V(k,l)-V(i,l)*pivot
end do
end if
enddo
end do
Minverse=V
end function Minverse
end Program nonlinear_system
Programming Example 12
Red characters are codes I wrote by myself today. 2018/01/05
But these can be changed like below using "matmul".
---------------------------------------------------------------------
do while ( (err>TOL).and.(k<k_max) )
k= k + 1
H=Hessian(x) !Get Hessian matrix as H using Hessian Function
Minv=Minverse(H) !Get inverse of Hessian matrix using Minverse Function
x=x-matmul(Minv,R) ! Update x
R = Residual(x) !Set Residual matrix as R.
err=sqrt(dot_product(R,R))
write(*,'(I10, $)') k
do i=1, m
write(*,'(F10.3, $)') x(i)
end do
write(*,'(E20.3)') err
end do
---------------------------------------------------------------------
This is the main code.
------------------------------------------------------------------------
Program nonlinear_system
! Global variables
integer, parameter:: m=3 ! Maximum number of variables
real(8):: S(m), H(m,m) ! Unknown variable vector S
real(8), parameter:: TOL=1D-6 ! Numerical tolerance
Call Guess(S)
Call Solve(S)
contains
Function Residual(x)
real(8):: Residual(m), x(m)
Residual(1)=-x(1)+2*x(2)+x(3)-2
Residual(2)=2*( (x(1)+3)**2) + 5*x(2)**2- (x(3)+1)**2
Residual(3)=(x(1)-5)*(x(2)+2) + 3
end Function Residual
Function Hessian(x)
real(8):: Hessian(m,m), x(m), x_(m), v(m), v_(m)
integer:: i,j
do i = 1, m
do j = 1, m
x_ = x; x_(j) = x(j) + TOL ! Perturb x
v_ = Residual(x_)
v = Residual(x)
Hessian(i,j) = ( v_(i) - v(i) ) / TOL
end do
end do
end Function Hessian
Subroutine Guess(x)
real(8), INTENT(OUT):: x(m) ! dummy variables
Integer:: i
Write(*,*) "Nonlinear system of", m, "equations"
do i = 1, m
write(*, '(A, I2, A)', advance="no") "Input the guessed value no.", i, " = "
Read(*,*) x(i)
end do
End Subroutine Guess
Subroutine Solve(x)
real(8), INTENT(INOUT):: x(m) ! dummy variables
! local variables
Integer, parameter:: k_max=50 ! Maximum iteration number
Integer:: k, n
real(8):: err, R(m), H(m,m),Minv(m,m),rs(m)
write(*,'(A10, $)') "Iteration"
do i=1, m
write(*,'(A9, I1,$)') "x", i
end do
write(*,'(A20)') "Norm of errors"
write(*, '(A)') repeat('-',60)
R = Residual(x)
err=sqrt(dot_product(R,R))
k=0
write(*,'(I10, $)') k
do i=1, m
write(*,'(F10.3, $)') x(i)
end do
write(*,'(E20.3)') ERR
do while ( (err>TOL).and.(k<k_max) )
k= k + 1
H=Hessian(x) !Get Hessian matrix as H using Hessian Function
Minv=Minverse(H) !Get inverse of Hessian matrix using Minverse Function
R = Residual(x) !Set Residual matrix as R.
rs=0.0
do i =1,m
do j =1,m
rs(i)=rs(i)+Minv(i,j)*R(j) !Get H(x_k)[-1]*r(x_k)
end do
x(i)=x(i)-rs(i) !Set New x
end do
R = Residual(x) !Set Residual matrix as R again.
err=sqrt(dot_product(R,R))
write(*,'(I10, $)') k
do i=1, m
write(*,'(F10.3, $)') x(i)
end do
write(*,'(E20.3)') err
end do
if (k==k_max) then
print*, "Divergence!"
end if
write(*, '(A)') repeat('-',60)
End Subroutine Solve
function Minverse(A)
real(8), dimension(:,:):: A
real(8), dimension(:,:), allocatable:: Minverse, B, V
real(8), dimension(:), allocatable:: temp
real(8), parameter:: TOL=1D-6
real(8):: pivot
integer:: i, j, jmax, k, n,l
n=size(A)**0.5
allocate(Minverse(n,n),B(n,n),V(n,n),temp(n))
B=A
V(:,:)=0.0
do i=1, n
V(i,i)=1.0
end do
do i=1, n
jmax=i
do j=i+1, n
if (abs(B(j,i))>abs(B(jmax,i))) then
jmax=j
temp=B(i,:);B(i,:)=B(jmax,:);B(jmax,:)=temp
temp=V(i,:);V(i,:)=V(jmax,:);V(jmax,:)=temp
end if
end do
pivot=B(i,i)
if (abs(pivot)<TOL) then
print *, "The matrix is singular!"
end if
B(i,:)=B(i,:)/pivot
V(i,:)=V(i,:)/pivot
do k =1,n
if (i .ne. k) then
pivot=B(k,i)
do l=1,n
B(k,l)=B(k,l)-B(i,l)*pivot
V(k,l)=V(k,l)-V(i,l)*pivot
end do
end if
enddo
end do
Minverse=V
end function Minverse
end Program nonlinear_system
Programming Example 11
Program report11
implicit none
character(len=50):: matrixfile
integer:: status=0, n
real(8):: r
real(8), dimension(:,:), allocatable:: Matrix, Inv_Matrix, Identity
integer:: i, j, row
write(*,*) "Enter the file name of matrix"
read(*,*) matrixfile
!===== Read file =====
open(1, file=matrixfile)
n=0
do
read(1, *, iostat=status) r
if (status/=0) exit
n=n+1
end do
rewind(1)
allocate(Matrix(n,n))
do i=1, n
read(1, *) Matrix(i, :)
end do
close(1)
!===== Process data =====
allocate(Inv_Matrix(n,n), Identity(n,n))
Inv_Matrix = Minverse(Matrix)
Identity = matmul(Matrix, Inv_Matrix)
!Check
print*, "The matrix before inversion."
do i=1, n
write(*,'(a)',advance="no") "|"
do j=1, n
write(*,'(E12.3)',advance="no") Matrix(i,j)
end do
write(*,*) "|"
end do
!===== Write file =====
open(2, file="invmat.dat")
print*,"The matrix after inversion"
do i=1, n
write(*,'(a)',advance="no") "|"
do j=1, n
write(*,'(E12.3)',advance="no") Inv_Matrix(i,j)
end do
write(*,*) "|"
end do
print*, "Check the identity matrix"
do i=1, n
write(*,'(a)',advance="no") "|"
do j=1, n
write(2,'(E12.3)',advance="no") Inv_Matrix(i,j)
write(*,'(E12.3)',advance="no") Identity(i,j)
end do
write(2,*) " "
write(*,*) "|"
end do
close(2)
Contains
Function Minverse(A)
real(8), dimension(:,:):: A
real(8), dimension(:,:), allocatable:: Minverse, B, V
real(8), dimension(:), allocatable:: temp
real(8), parameter:: TOL=1D-6
real(8):: pivot
integer:: i, j, jmax, k, n,l
n=size(A)**0.5
allocate(Minverse(n,n),B(n,n),V(n,n),temp(n))
B=A
V(:,:)=0.0
do i=1, n
V(i,i)=1.0
end do
do i=1, n
jmax=i
do j=i+1, n
if (abs(B(j,i))>abs(B(jmax,i))) then
jmax=j
temp=B(i,:);B(i,:)=B(jmax,:);B(jmax,:)=temp
temp=V(i,:);V(i,:)=V(jmax,:);V(jmax,:)=temp
end if
end do
pivot=B(i,i)
if (abs(pivot)<TOL) then
print *, "The matrix is singular!"; stop
end if
B(i,:)=B(i,:)/pivot !All pivots on B(i,:) are divide by diagnole in order to set diagnole 1.
V(i,:)=V(i,:)/pivot !Apply the above process for V which leads to Inverse of the matrix.
!This is the wrong code I wrote.
! do j=1,n
! B(i,j)=B(i,j)/B(i,i)
! V(i,j)=V(i,j)/B(i,i)
! end do
!If we failed to set pivot=B(i,i), the value is changeable so we can't get correct value.
do k =1,n
if (i .ne. k) then
pivot=B(k,i) !Set pivot B(k,i) which means the number located on the column the above process works.
do l=1,n
B(k,l)=B(k,l)-B(i,l)*pivot !B(k,i) is changed to new row in order to change one column into 0 .
V(k,l)=V(k,l)-V(i,l)*pivot !Apply above process for V.
end do
end if
enddo
end do
!This is the wrong code I wrote.
! do l=1,n
! B(k,l)=B(k,l)-B(i,l)*B(k,i)
! V(k,l)=V(k,l)-V(i,l)*B(k,i)
! end do
!If we failed to set pivot=B(k,i),the same thing as above will happen.
Minverse=V
end Function Minverse
End Program report11
京大地球工学科国際コースについて【1】
国際コースに関する記事は移行しました(2020/02/13)
こちらへ
http://yuma2012.hateblo.jp/entry/2020/02/13/042247
眠い、前文省略します。
もともと文がうまくないんだから、ここで面白さを求めても駄目だわ。
今はインドネシア人の友人と原発のプレゼンを作ってます。あまりに僕のやる気がなく、挙句の果てにブログを書き始めたのでとうとうキレてます。
ここでは僕の所属する京都大学工学部地球工学科国際コースとは何たるかを書きます。なんでこんなの書くかといったら簡単。来年人が全然入らないと寂しいからです。では早速。
1.地球工学科とは?
まずは、大前提から。京大の工学部には6つの科があります。その一つが地球工学科で、土木・資源・環境の3分野で成り立っています。土木というとよくわからないかもしれませんが、端的に言ってインフラです。僕の勝手なイメージですが、土木=インフラ整備(ハードの整備)+計画系(ソフトの整備)な感じ。インフラはご想像の通り、ダムとか道路とか沿岸整備とか。計画は都市計画とか交通マネジメントとかですかね。ちなみに僕は交通か防災に行きたいなぁ。そういえば、内閣官房付になった藤井教授は交通系だったはず。
まあそんな感じ。ちなみに僕は合格してから内容を知った。
2.国際コースとは?
先ほども言った通り、地球工には3つ分野がありまして、その配属が3年に上がるときにあります。国際コースは土木科の中にあるので、土木しかできませーーん。しかし、国際コースは一回生の入学前に分属されてしまいます。そのあとは出ることしかできません!逆に言えば、研究室配属まで何のコース分けもないです。
ではまず基本的な情報をまとめていきます。
・すべての授業(一般教養などすべて。第二外国語を除く)が英語。
・留学生がクラスの半分~いる。国籍はアジアがほとんど。たまにエジプトとかモンゴルとか。
・課題が過大
・発表系の授業が多め。プレゼンたくさん。熱力学でプレゼン。専門でプレゼン。実験でプレゼン。一般教養でプレゼン。少人数セミナーでプレゼン。プレレレレレレ。
・出席点の比率高め。
・ほぼすべての授業が20人前後の少人数で行われる。
・3年次に海外インターン
・卒業論文が英語
国際コースのここが素晴らしい!!!
・英語は当然スーパー上達する。わしゃもうネイティブレベル。
・面白い人が多い。
・クラス仲が良い。
・いろいろな文化の違いを感じれる
・就職余裕
・世界に羽ばたく「グローーーバル人材www」になれる。
・他の学部学科の人からかなり羨ましがられる
・ドヤれる
・イキれる
・学畜になれる
・いつでも辞めて日本語コースに移動できる。
・GORILAとかいう呪いみたいな制度から解放された自由地区
(上記は75%の事実と25%の偏見を基に作成)
国際コースのここがクソ
・課題が大変。僕みたいに要領悪いとサークル行けへん
・したがって当然部活やるとくそ大変。(ただし、ギリギリ単位だけ取るならまあいける?)
・常に立ちはだかる言語の壁
・就職そんな楽じゃない
・もうなんか色々とFUCK
・その他悪口を順次受け付けています。国際コースの人は@yuma2011nまで
はあもうなんかそんな感じ。詳しい説明は以下の通り。
☆授業~~~
ほぼすべての授業が基本的に全部英語で行われます。
土木の専門授業はもちろん地球工学の主に外国人教授が授業をされます。が、日本人の教授も英語で授業をされます。外国人教授の国籍はあまりにバラバラなので、特に傾向を感じません。日本人の教授はかなり英語で苦労されている方も多いらしく、先輩曰く教授の英語力と業績に特に相関はないらしいです。基本的に常に語学で苦労しているのは教える方も教わる方も日本人です。専門科目はほとんどペーパーのテストで評価されます。
さらに、自然科目(例えば力学や熱力学)、英語科目、情報科目なども地球工の外国人教授が担当しています。唯一、一年次の数学は数学科の先生が担当します。二年次からの数学はこれまた地球工の先生が担当します。これは驚いた。何の科目とっても同じ人たち出てくんの。草でしょ。
一般教養の人文社会系や統合・健康群などは他の学科の学生と同じように受けますが、それらもすべてE2という英語の授業の中で選んで取ります。だいたいの授業がレポートかディスカッション、授業態度で評価されます。
ここで問題があって、人社の授業は前後期合わせて700ありますが、我々が取れる英語の授業(E2科目)は90個あまりしかありません。そのうち他の科目と被らないように取ると、選択肢はかなり狭まります。しかも、来年から京都大学はE2科目の人数制限を厳しくするそうです。ますます、人社E2事情は厳しくなるのです。クソ京都大学マジで死
ええと...気を取り直して。
唯一、第二外国語だけは他の学生と完全に同じです。ちなみに僕は韓国語。二コマのうち一つは日本人、もう一つは韓国人の教授なので、今季の僕が取っている授業で日本人の教授は一人だけです。
面倒になったのでこれから先のことは次回に回します。文体が荒れてすみません。なにぶん暇つぶしに書いたので。反省しません。
えええと国際コースは今年でできてから7年目ですので、まだまだ僕たちはマウスですね。これからどうなるかわかりませんが、超面白いので(笑)ぜひ入ってください。
Programming Example 10
加筆:
Jacobi メソッドとGauss-Seidelの中でわざわざTempを使ってるのはA(i:j)の形で一々使うと、メモリ効率が悪い(どっかに書いてあった)ので、置き換えただけです。
I used Temp in two sessions Jacobi and Gauss-Seidel method in order to avoid the situation A(i:j) uses the high rate of RAM performances.
Someone, I don’t recall who well, said that using A(i:j) many times causes ineffective performance.
!Yuma
!This proram has many "dirty" expressions. Don't care.
program report10
implicit none
integer,parameter:: t = 10000
real(8)::A(t,t),B(t),X0(t)=0.0,X(t)=0.0,Jres,Temp
integer(8)::N,i,j,jmax,r,k,c=0.0
logical judge
print*, "Please set the number of columns and rows (n-n matrix).(N<=10000) "
read*, N
!Set format20
20 format(I2,(a),I2,3x,(a))
!Read Matrix A
do i = 1, N
do j = 1, N
write(*,20) i,"*",j, "On matrix A"
read(*,*) A(i,j)
end do
end do
!Read vector B
do i = 1, N
write(*,20) i,"*",n, "On vector B "
read*, B(i)
end do
!Set Format10 which will be used repeatedly
10 format(f10.3)
!Display the original A and B
print*, "Matrix and vector before pivoting"
do i =1, N
write(*,fmt='(a)',advance='no') "|"
do j = 1,N
write(*,10,advance='no') A(i,j)
end do
write(*,fmt='(a)',advance='no') "|"
write(*,10) B(i)
end do
print*, "-----------------------------------------------------------------"
!Judge whether diagnole has 0 or not on matrix A
judge = .false.
do i = 1, N
if (A(i,i)==0) then
judge = .true.
end if
end do
!Reorder the matrix A
if (judge) then
do r =1,N-1
jmax =A(r,r)
do j = r + 1,N
if (abs(jmax)<abs(A(j,r))) then
jmax = j
end if
end do
if (jmax /= A(r,r)) then
do k = 1,N
A(r,k)= A(r,k)+A(jmax,k);A(jmax,k)=A(r,k)-A(jmax,k);A(r,k)=A(r,k)-A(jmax,k)
end do
b(r)=b(jmax)+b(r);b(jmax)=b(r)-b(jmax);b(r)=b(r)-b(jmax)
end if
end do
end if
!Display the reordered A and B
print*, " "
print*, "Matrix and vector after pivoting"
do i =1, N
write(*,fmt='(a)',advance='no') "|"
do j = 1,N
write(*,10,advance='no') A(i,j)
end do
write(*,fmt='(a)',advance='no') "|"
write(*,10) B(i)
end do
print*, "-----------------------------------------------------------------"
!Jacobi Method
print*, " "
print*, "Jacobi method with the numerical tolerance 0.100E-02"
print*, "-----------------------------------------------------------------"
write(*,fmt='(a)',advance='no') "Iteration"
do i = 1, N
write(*,'(a)',advance='no') " X"
write(*,'(I1)',advance='no') i
end do
write(*,'(a)') " Residual"
print*, "-----------------------------------------------------------------"
Jres = 1.0
do while (sqrt(Jres) >1.0E-3)
write(*,'(I3)',advance='no') c
do k=1,N
write(*,10,advance='no') x(k)
end do
if (c==0) then
write(*,*) " -"
else
write(*,'(E10.3)') Jres
end if
Jres = 0
do i= 1, N
X0(i)= X(i)
end do
do i= 1, N
Temp = B(i)
do j= 1, N
if (j /= i) then
Temp = Temp - A(i,j)*X0(j)
end if
end do
X(i)= Temp/A(i,i)
end do
do i = 1,N
Jres = Jres + (x0(i)-x(i))**2
end do
c= c + 1
end do
print*, "-----------------------------------------------------------------"
!The end of Jacobi
print*, " "
c = 0
!Gauss-Seidel
print*, "Gauss-Seidel method with the numerical tolerance 0.100E-02"
print*, "-----------------------------------------------------------------"
write(*,fmt='(a)',advance='no') "Iteration"
do i = 1, N
write(*,'(a)',advance='no') " X"
write(*,'(I1)',advance='no') i
end do
write(*,'(a)') " Residual"
print*, "-----------------------------------------------------------------"
do i =1, N
x(i)=0
end do
Jres = 1.0
do while (sqrt(Jres)>1.0E-3)
write(*,'(I3)',advance='no') c
do k=1,N
write(*,10,advance='no') x(k)
end do
if (c==0) then
write(*,*) " -"
else
write(*,'(E10.3)') Jres
end if
Jres = 0
do i= 1, N
X0(i)= X(i)
end do
do i= 1, N
Temp= B(i)
do j= 1, N
if (j /= i) then
Temp = Temp - A(i,j)*X(j)
end if
end do
X(i)= Temp/A(i,i)
enddo
do i = 1,N
Jres = Jres + (x0(i)-x(i))**2
end do
c = c + 1
end do
print*, "-----------------------------------------------------------------"
end program report10
Result
Please set the number of columns and rows (n-n matrix).(N<=10000)
4
1* 1 On matrix A
2
1* 2 On matrix A
0
1* 3 On matrix A
2
1* 4 On matrix A
-3
2* 1 On matrix A
0.25
2* 2 On matrix A
0
2* 3 On matrix A
0.25
2* 4 On matrix A
6
3* 1 On matrix A
-5
3* 2 On matrix A
1
3* 3 On matrix A
-1.5
3* 4 On matrix A
2
4* 1 On matrix A
1
4* 2 On matrix A
1
4* 3 On matrix A
1
4* 4 On matrix A
1
1* 4 On vector B
9
2* 4 On vector B
7.5
3* 4 On vector B
-18
4* 4 On vector B
10
Matrix and vector before pivoting
| 2.000 0.000 2.000 -3.000| 9.000
| 0.250 0.000 0.250 6.000| 7.500
| -5.000 1.000 -1.500 2.000| -18.000
| 1.000 1.000 1.000 1.000| 10.000
-----------------------------------------------------------------
Matrix and vector after pivoting
| -5.000 1.000 -1.500 2.000| -18.000
| 1.000 1.000 1.000 1.000| 10.000
| 2.000 0.000 2.000 -3.000| 9.000
| 0.250 0.000 0.250 6.000| 7.500
-----------------------------------------------------------------
Jacobi method with the numerical tolerance 0.100E-02
-----------------------------------------------------------------
Iteration X1 X2 X3 X4 Residual
-----------------------------------------------------------------
0 0.000 0.000 0.000 0.000 -
1 3.600 10.000 4.500 1.250 0.135E+03
2 4.750 0.650 2.775 0.912 0.918E+02
3 3.263 1.562 1.119 0.936 0.579E+01
4 3.951 4.682 2.642 1.067 0.125E+02
5 4.171 2.339 2.150 0.975 0.579E+01
6 3.813 2.704 1.792 0.987 0.390E+00
7 3.998 3.408 2.167 1.016 0.671E+00
8 4.038 2.819 2.027 0.993 0.369E+00
9 3.953 2.942 1.952 0.997 0.281E-01
10 4.002 3.098 2.043 1.004 0.352E-01
11 4.008 2.951 2.004 0.998 0.232E-01
12 3.988 2.989 1.989 0.999 0.210E-02
13 4.001 3.023 2.011 1.001 0.181E-02
14 4.002 2.987 2.000 1.000 0.143E-02
15 3.997 2.998 1.997 1.000 0.157E-03
16 4.000 3.006 2.003 1.000 0.910E-04
17 4.000 2.997 2.000 1.000 0.874E-04
18 3.999 3.000 1.999 1.000 0.117E-04
19 4.000 3.001 2.001 1.000 0.448E-05
20 4.000 2.999 2.000 1.000 0.525E-05
-----------------------------------------------------------------
Gauss-Seidel method with the numerical tolerance 0.100E-02
-----------------------------------------------------------------
Iteration X1 X2 X3 X4 Residual
-----------------------------------------------------------------
0 0.000 0.000 0.000 0.000 -
1 3.600 10.000 4.500 1.250 0.135E+03
2 4.750 0.650 2.775 0.912 0.918E+02
3 3.263 1.562 1.119 0.936 0.579E+01
4 3.951 4.682 2.642 1.067 0.125E+02
5 4.171 2.339 2.150 0.975 0.579E+01
6 3.813 2.704 1.792 0.987 0.390E+00
7 3.998 3.408 2.167 1.016 0.671E+00
8 4.038 2.819 2.027 0.993 0.369E+00
9 3.953 2.942 1.952 0.997 0.281E-01
10 4.002 3.098 2.043 1.004 0.352E-01
11 4.008 2.951 2.004 0.998 0.232E-01
12 3.988 2.989 1.989 0.999 0.210E-02
13 4.001 3.023 2.011 1.001 0.181E-02
14 4.002 2.987 2.000 1.000 0.143E-02
15 3.997 2.998 1.997 1.000 0.157E-03
16 4.000 3.006 2.003 1.000 0.910E-04
17 4.000 2.997 2.000 1.000 0.874E-04
18 3.999 3.000 1.999 1.000 0.117E-04
19 4.000 3.001 2.001 1.000 0.448E-05
20 4.000 2.999 2.000 1.000 0.525E-05
-----------------------------------------------------------------