You are on page 1of 5

Q1/

program solve_equations_by_inverse_matrix
implicit none
integer,parameter::n=3
real,dimension (n)::b,x
real,dimension(n,n)::a,a1
integer::i,j,k,l
real::z
data a/25,64,144,5,8,12,1,1,1/
data a1/1,3*0,1,3*0,1/
data b/106.8,177.2,279.2/
!divided all elements of a & a1 by a(i,i)
do i=1,n
z=a(i,i)
do j=1,n
a(i,j)=a(i,j)/z
a1(i,j)=a1(i,j)/z
enddo
!make zero all entries in column a(j,i) & a1(j,i)
do j=i+1,n
z=a(j,i)
do k=1,n
a(j,k)=a(j,k)-z*a(i,k)
a1(j,k)=a1(j,k)-z*a1(i,k)
enddo
enddo ; enddo
!subtract appropiate multiple of row j from j-1
do i=1,n-1

1
do j=i+1,n
z=a(i,j)
do l=1,n
a(i,l)=a(i,l)-z*a(j,l)
a1(i,l)=a1(i,l)-z*a1(j,l)
enddo
enddo
enddo
do i=1,n
write(*,60)(a(i,j),j=1,n) , (a1(i,j),j=1,n)
60 format(2x,3(f10.6),10x,3(f10.6))
enddo
print*,"********************"
CALL MULTI (a1,b,x)
do i=1,n
print 10,"x",i,"=",x(i)
enddo
10 format(2x,a,i1,a,f10.5)
end
subroutine multi(a1,b,x)
implicit none
integer,parameter::n=3
real,dimension (n)::b,x
real,dimension(n,n)::a1
integer::i,j,k
do i=1,n
do j=1,n
x(i)=0

2
do k=1,n
x(i)=x(i)+a1(i,k)*b(k)
enddo;enddo;enddo;end

Q2/
program Iterpolation_by_lagrange
implicit none
real,dimension(4)::x,y
real::xp ,sum
open (unit=9,file="fr.dat")
data x /4.5,6,7.5,9/
data y/0.63,0.53,0.43,0.36/
xp=6.25
call aa(x,y,xp,sum)
write(9,1)"value of density for altitude ",xp,"=",sum
1 format(2x,a,f5.3,a,1x,f10.5)
end

subroutine aa(x,y,xp,sum)
implicit none
real,dimension(4)::x,y
real::xp ,sum,p
integer::n=4 ,i,j
do i=1,n ; p=1
do j=1,n
if (i.eq.j) cycle
p=p*(xp-x(j))/(x(i)-x(j)) ; enddo
sum=sum+p*y(i) ; enddo

3
end

Q3/
program central_difference_method
implicit none
real::h,a,first,second,f1,f2,t,f
f(t)=t**4-2*t**3-6*t**2+9*t
read(*,*)h,a
first=(f(a+h)-f(a-h))/(2*h)
second=(f(a+h)-(2*f(a))+f(a-h))/(h**2)
f1=first
f2=second
write(*,9)"for T=",a,"VELOCITY=",f1
write(*,9)"for T=",a,"ACCELERATION=",f2
9 format(3x,a,f7.3,2x,a,2x,f7.3)
end

Q4/
Program determinant ; implicit none
Integer, parameter::n=3, m=5
Integer, dimension (n,m):: a
Integer:: i, j, det1, det2, det
character(len=50)::ff
Read(*,*) ((a(i,j),j=1,n),i=1,n)
Do i=1,n
do j=1,n-1
a(i,n+j)=a(I,j) ; enddo; enddo
do i=1,n ; det1=1 ; det2=1

4
do j=1,n
det1=det1*a(j,i+j-1) ; det2=det2*a(j,2*n-j-i+1) ;enddo
det=det+det1-det2 ; enddo
write(*,6) "determinant=", det ;6 format(2x,a,2x,i8);
write(*,8)"the matrix is",ff(det)
8 format(1x,a,1x,a) ; end

function ff(det)
character(len=50)::ff
integer::det
if(det==0)then
ff="singular"
else
ff="non-singular"
endif
end

You might also like