목차
1. 함수처리에 관한 설명
- 수반행렬을 이용한 방법
- Gauss-Jordan 소거법을 이용한 방법
2. 사용함수에 관한 설명
3. 결과 값
4. 소스
- 수반행렬을 이용한 방법
- Gauss-Jordan 소거법을 이용한 방법
2. 사용함수에 관한 설명
3. 결과 값
4. 소스
본문내용
t % (n - 1)
minor[minor_x][minor_y] = p[x][y]
count = count + 1
end if
y = y + 1
end while
end while
return minor
End
algorithm Gauss(double** p, int n)
i = 0, j = 0 x = 0
y = 0, z = 0
multi_temp, swap_temp
temp = SortMtx(p, n)
data = CreateMtx(n)
while i < n then
while j < n then
if temp[i][i] == 0 then
y = i
while temp[i][y] ==0 then
y = y + 1
end while
z = 0
while z < 2*n then
swap_temp = temp[y][z]
temp[y][z] = temp[i][z]
temp[i][z] = swap_temp
z = z + 1
end while
if i == j then continue
if temp[j][i] != 0 then
multi_temp =
temp[j][i]/temp[i][i]
x = 0
while x < 2*n
temp[j][x] = temp[j][x]
-1*temp[i][x]*multi_temp
x = x +1
end while
end while
end while
i = 0, j = 0
while i < n then
while j < n then
data[i][j] =
temp[i][j+n]/temp[i][i]
j = j +1
end while
i = i +1
end while
return data
End
algorithm Adjoint(double** p, int n)
i = 1 , j = 1, temp_sign = 1
fanal_value = CreateMtx(n)
max_det = determinant(p, n)
**temp_p, temp_v
while i <= n
while j <=n temp_p = MinorMtx(p, n, i, j)
if ((i + j) % 2) == 0 then
temp_sign = 1
else temp_sign = -1temp_v = temp_sign
*determinant(temp_p, n-1)
DestructMtx(temp_p, n-1)
fanal_value[j - 1][i - 1] =
temp_v/max_det
j = j +1
end while
i = i +1
end while
return fanal_value
End
algorithm main(adjoint.c)
n = (int)sqrt(cnt)
p = CreateMtx(n)
i = 0, j = 0 k = 0
**fanal_value_ad
double max_det
count = 0
ifp = fopen("in_file.txt", "r")
ofp = fopen("outfile.txt", "w")
while fscanf(ifp, "%lf", &val) == 1 then
cnt = cnt + 1
end while
fclose(ifp)
ifp = fopen("in_file.txt", "r")
while i < n then
while j < n then
fscanf(ifp, "%lf", &val)
p[i][j] = val
j = j + 1
end while
end while
max_det = determinant(p, n)
if max_det == 0 then
printf("행렬식이 0이라 종료“)
return 0
end if
fanal_value_ad = Adjoint(p, n)
fprintf(ofp, "\n- Gauss-Jordan 소거법
을 이용한 역행렬 -")
i = 0, k = 0
while j < n then
fprintf(ofp, "\n")
while k < n then
fprintf(ofp, "%5.2lf ",
fanal_value_ga[j][k])
k = k + 1
end while
j = j + 1
end while
DestructMtx(p, n)
DestructMtx(fanal_value_ad, n)
fclose(ifp)
fclose(ofp)
printf("성공적으로 계산되었습니다.
\n\noutfile.txt를 확인해보세요\n\n")
return 0
End
algorithm main(gauss.c)
n = (int)sqrt(cnt)
p = CreateMtx(2*n)
i = 0, j = 0 k = 0
**fanal_value_ga
double max_det
count = 0
ifp = fopen("in_file.txt", "r")
ofp = fopen("outfile.txt", "w")
while fscanf(ifp, "%lf", &val) == 1 then
cnt = cnt + 1
end while
fclose(ifp)
ifp = fopen("in_file.txt", "r")
while i < n then
while j < n then
fscanf(ifp, "%lf", &val)
p[i][j] = val
if i == j then
p[i][j+n] = 1
else
p[i][j+n] = 0
j = j + 1
end while
end while
max_det = determinant(p, n)
if max_det == 0 then
printf("행렬식이 0이라 종료“)
return 0 end if
fanal_value_ga = Gauss(p, n)
fprintf(ofp, "\n- Gauss-Jordan 소거법
을 이용한 역행렬 -")
i = 0, k = 0
while j < n then
fprintf(ofp, "\n")
while k < n then
fprintf(ofp, "%5.2lf ",
fanal_value_ga[j][k])
k = k + 1
end while
j = j + 1
end while
DestructMtx(p, n)
DestructMtx(fanal_value_ga, n)
fclose(ifp)
fclose(ofp)
printf("성공적으로 계산되었습니다.
\n\noutfile.txt를 확인해보세요\n\n")
return 0
End
minor[minor_x][minor_y] = p[x][y]
count = count + 1
end if
y = y + 1
end while
end while
return minor
End
algorithm Gauss(double** p, int n)
i = 0, j = 0 x = 0
y = 0, z = 0
multi_temp, swap_temp
temp = SortMtx(p, n)
data = CreateMtx(n)
while i < n then
while j < n then
if temp[i][i] == 0 then
y = i
while temp[i][y] ==0 then
y = y + 1
end while
z = 0
while z < 2*n then
swap_temp = temp[y][z]
temp[y][z] = temp[i][z]
temp[i][z] = swap_temp
z = z + 1
end while
if i == j then continue
if temp[j][i] != 0 then
multi_temp =
temp[j][i]/temp[i][i]
x = 0
while x < 2*n
temp[j][x] = temp[j][x]
-1*temp[i][x]*multi_temp
x = x +1
end while
end while
end while
i = 0, j = 0
while i < n then
while j < n then
data[i][j] =
temp[i][j+n]/temp[i][i]
j = j +1
end while
i = i +1
end while
return data
End
algorithm Adjoint(double** p, int n)
i = 1 , j = 1, temp_sign = 1
fanal_value = CreateMtx(n)
max_det = determinant(p, n)
**temp_p, temp_v
while i <= n
while j <=n temp_p = MinorMtx(p, n, i, j)
if ((i + j) % 2) == 0 then
temp_sign = 1
else temp_sign = -1temp_v = temp_sign
*determinant(temp_p, n-1)
DestructMtx(temp_p, n-1)
fanal_value[j - 1][i - 1] =
temp_v/max_det
j = j +1
end while
i = i +1
end while
return fanal_value
End
algorithm main(adjoint.c)
n = (int)sqrt(cnt)
p = CreateMtx(n)
i = 0, j = 0 k = 0
**fanal_value_ad
double max_det
count = 0
ifp = fopen("in_file.txt", "r")
ofp = fopen("outfile.txt", "w")
while fscanf(ifp, "%lf", &val) == 1 then
cnt = cnt + 1
end while
fclose(ifp)
ifp = fopen("in_file.txt", "r")
while i < n then
while j < n then
fscanf(ifp, "%lf", &val)
p[i][j] = val
j = j + 1
end while
end while
max_det = determinant(p, n)
if max_det == 0 then
printf("행렬식이 0이라 종료“)
return 0
end if
fanal_value_ad = Adjoint(p, n)
fprintf(ofp, "\n- Gauss-Jordan 소거법
을 이용한 역행렬 -")
i = 0, k = 0
while j < n then
fprintf(ofp, "\n")
while k < n then
fprintf(ofp, "%5.2lf ",
fanal_value_ga[j][k])
k = k + 1
end while
j = j + 1
end while
DestructMtx(p, n)
DestructMtx(fanal_value_ad, n)
fclose(ifp)
fclose(ofp)
printf("성공적으로 계산되었습니다.
\n\noutfile.txt를 확인해보세요\n\n")
return 0
End
algorithm main(gauss.c)
n = (int)sqrt(cnt)
p = CreateMtx(2*n)
i = 0, j = 0 k = 0
**fanal_value_ga
double max_det
count = 0
ifp = fopen("in_file.txt", "r")
ofp = fopen("outfile.txt", "w")
while fscanf(ifp, "%lf", &val) == 1 then
cnt = cnt + 1
end while
fclose(ifp)
ifp = fopen("in_file.txt", "r")
while i < n then
while j < n then
fscanf(ifp, "%lf", &val)
p[i][j] = val
if i == j then
p[i][j+n] = 1
else
p[i][j+n] = 0
j = j + 1
end while
end while
max_det = determinant(p, n)
if max_det == 0 then
printf("행렬식이 0이라 종료“)
return 0 end if
fanal_value_ga = Gauss(p, n)
fprintf(ofp, "\n- Gauss-Jordan 소거법
을 이용한 역행렬 -")
i = 0, k = 0
while j < n then
fprintf(ofp, "\n")
while k < n then
fprintf(ofp, "%5.2lf ",
fanal_value_ga[j][k])
k = k + 1
end while
j = j + 1
end while
DestructMtx(p, n)
DestructMtx(fanal_value_ga, n)
fclose(ifp)
fclose(ofp)
printf("성공적으로 계산되었습니다.
\n\noutfile.txt를 확인해보세요\n\n")
return 0
End
소개글