2 개의 배열 사이의 스칼라 곱을 계산하는 프로그램을 수행하고 있습니다. 결과는 스칼라 실제 값입니다. 내 솔루션 차원을 (1,1)입니다 매트릭스를 사용하는 것입니다. 이 문제는 없지만 줄을 추가하기 만하면됩니다.FORTRAN : 전달하는 동안 실수가 실수 (:, :
res=tmp_2(1,1)
세그먼트 결함이 있습니다. 라는
call product(u, v, m0, 3, res)
print*, "The result is ", res
call product(u, u, m0, 3, umod)
umod=sqrt(umod)
call product(v, v, m0, 3, vmod)
vmod=sqrt(vmod)
angle=acos(res/(umod*vmod))
print*, "The angle is: ", angle
contains
subroutine product(v, u, metr, n, res)
real, dimension(:,:), intent(in) :: metr
real, dimension(:), intent(in) :: u, v
integer, intent(in) :: n
real, optional, intent(out) :: res
real, dimension(:,:), allocatable :: v_t, tmp, tmp_1, tmp_2
integer :: i, j
allocate(tmp(n,1))
allocate(tmp_1(n,1))
allocate(tmp_2(1,1))
allocate(v_t(1,n))
call vec_mat(v, tmp, n) !convert vector(n) to matrix(n,1) to be able to
!operate with my multiplication subroutine
call vec_mat(u, tmp_1, n)
call mattrans(tmp, n, 1, v_t) !matrix transposition
deallocate(tmp)
allocate(tmp(1,n))
call matmul(v_t, metr, 1, n, n, tmp) !matrixes moltiplication
call matmul(tmp, tmp_1, 1, n, 1, tmp_2)
res=tmp_2(1,1) !!!!!!!!!HERE IS THE PROBLEM!!! <---------------
end subroutine product
모든 서브 루틴 모듈에 있지만, 모두의 테스트 및 작품 : 코드입니다.
P. 내 서버는 스페인어이므로 실제 오류는 "세그먼트 오류 (Violacion de segmento ('core'generado) ')입니다.
은 'res'가 실제로 존재합니까? –
내가 선언했다는 뜻입니까? 그래, 내가 했어. –
아니요, 선택적 인수입니다. 인수 목록에 있어야합니다. –