Assignment 4 Code Input Output
Assignment 4 Code Input Output
Open(unit=41,file='CurrentOutput.txt')
exact=fd(t)
write(41,*)"The Exact Value of Current is:",exact
write(41,'(/)')
2 format(t37,"Approximation Value",6x,"Error")
write(41,2)
h=-.25
do i=0,2
m(i)=f(t+i*h)
n(i)=f(t-i*h)
end do
I1=(m(1)-n(1))/(2*h)
Write(41,*)"Using Three Point Midpoint Formula:",I1,abs(I1-exact)
h=.25
do i=0,2
m(i)=f(t+i*h)
n(i)=f(t-i*h)
end do
I2=(-3*m(0)+4*m(1)-m(2))/(2*h)
Write(41,*)"Using Three Point Endpoint Formula:",I2,abs(I2-exact)
h=.5
do i=1,2
m(i)=f(t+i*h)
n(i)=f(t-i*h)
end do
I3=(n(2)-8*n(1)+8*m(1)-m(2))/(12*h)
Write(41,*)"Using Five Point Midpoint Formula:",I3,abs(I3-exact)
h=.5
do i=0,4
m(i)=f(t+i*h)
n(i)=f(t-i*h)
end do
I4=(-25*m(0)+48*m(1)-36*m(2)+16*m(3)-3*m(4))/(12*h)
Write(41,*)"Using Five Point Endpoint Formula:",I4,abs(I4-exact)
end program
function f(t)
implicit none
real::f,t
f=60-60*exp(-t/5)
end function
function fd(t)
implicit none
real::fd,t
fd=12*exp(-t/5)
end function
Output: CurrentOutput.txt
The Exact Value of Current is: 4.41455364
Open(unit=5,file='RichardOutPut.txt')
exact=fd(x0)
Write(5,*)"The Exact Value is: ",exact
do i=0,4
n(i+1)=h/2**i
end do
do i=1,5
d(i,1)=(f(x0+n(i))-f(x0-n(i)))/(2*n(i))
end do
do j=2,5
do i=j,5
d(i,j)=(4**(j-1)*d(i,j-1)-d(i-1,j-1))/(4**(j-1)-1)
end do
end do
write(5,'(/)')
Write(5,'(t5,"O(h**2)",10x,"O(h**4)",10x,"O(h**6)",10x,"O(h**8)",10x,"O(h**10)")')
10 format(90('_'))
write(5,10)
Do i=1,5
Write(5,*)(d(i,j),j=1,i)
End Do
end program
function f(x)
real::x
f=x*exp(x)
end function
function fd(x)
real:: fd,x
fd=x*exp(x)+exp(x)
end function
Output: RichardOutPut.txt
The Exact Value is: 22.1671677
do i=1,7
read(10,*) t(i),x(i)
end do
! when t=0.0 s
v1=(x(2)-x(1))/(t(2)-t(1))
a1=(x(3)-2*x(2)+x(1))/((t(3)-t(2))*(t(2)-t(1)))
! when t=0.6 s
v2=(x(7)-x(6))/(t(7)-t(6))
a2=(x(7)-2*x(6)+x(5))/((t(7)-t(6))*(t(6)-t(5)))
write(12,'(t17,"velocity",8x,"acceleration")')
write(12,'(50("_"))')
write(12,*) "when t=0.0s:",v1,a1
write(12,*) "when t=0.6s:",v2,a2
close(10)
close(12)
end program motion
Input: 3input.txt
0.0 30.13
0.1 31.62
0.2 32.87
0.3 33.64
0.4 33.95
0.5 33.81
0.6 33.24
Output: 3output.txt
velocity acceleration
__________________________________________________
when t=0.0s: 14.9000168 -24.0003586
when t=0.6s: -5.69999552 -43.0000229
open(unit=4,file='integralOutput.txt')
do i=1,n-1
m(i)=f(a+i*h)
end do
I4=(3*h/10)*(f(a)+5*m(1)+m(2)+6*m(3)+m(4)+5*m(5)+f(b))
write(4,'(a,3f14.10)')"Using Weddles Formula the value is:
",I4,Abs(exact-I4),Abs(exact-I4)/exact
end program
function f(x)
implicit none
real::f,x
f=-1/((x-1)*(2+sqrt(2.)-2*x))
end function
function fd(x)
implicit none
real::fd,x
fd=-(1/sqrt(2.))*log(abs((x-1)/(sqrt(2.)-2*(x-1))))
end function
Output: integralOutput.txt
The exact Value is: 0.430767536
Aproximation Value Abs Error Relative
Error
Using Trapezoidal Rule the value is: 0.431104422 3.36885452E-04
7.82058574E-04
Using Simpson's 1/3 Rule the value is: 0.430768639 1.10268593E-06
2.55981672E-06
Using Simpson's 3/8 Rule the value is: 0.430769980 2.44379044E-06
5.67310735E-06
Using Weddles Formula the value is: 0.0475881808 0.3831793666 0.8895270228
a = 0.0
b = 1.0
tol = 1.0e-5
do i = 2,nmax
n = 2**(i-1)
h = (b - a) /n
s=0.0
do k = 1, n/2
s= s+f(a +(2*k-1)*h)
end do
do j = 2, i
R(i,j) = R(i,j-1) + (R(i,j-1) - R(i-1,j-1)) / (4.0**(j-1) - 1.0)
end do
write(8,*)( R(i,j),j = 1, i)
end program
Output: RombergOutPut.txt
0.774999976 0.783333302
0.782794118 0.785392165 0.785529435
0.784747124 0.785398126 0.785398543 0.785396457
0.785235405 0.785398185 0.785398185 0.785398185 0.785398185
Romberg integration result: 0.785398185
Estimated error: 1.72853470E-06