我不太擅长编程,但不幸的是,我必须学习它,继续前进,我被要求做一些关于矢量编程的工作。
我必须弄清楚点积和点积
我到目前为止:
REAL :: x , y , z
END TYPE myvector
CONTAINS
TYPE ( myvector ) FUNCTION vect_add (a , b )
IMPLICIT NONE
TYPE ( myvector ) , INTENT (IN) :: a , b
vect_add % x = a % x + b % x
vect_add % y = a % y + b % y
vect_add % z = a % z + b % z
END FUNCTION vect_add
TYPE ( myvector ) FUNCTION vect_scale ( vector , scalar )
IMPLICIT NONE
TYPE ( myvector ) , INTENT (IN) :: vector
REAL , INTENT (IN) :: scalar
vect_scale % x = vector % x * scalar
vect_scale % y = vector % y * scalar
vect_scale % z = vector % z * scalar
END FUNCTION vect_scale
TYPE ( myvector ) FUNCTION vect_sub (a , b )
IMPLICIT NONE
TYPE ( myvector ) , INTENT (IN) :: a , b
vect_sub % x = a % x - b % x
vect_sub % y = a % y - b % y
vect_sub % z = a % z - b % z
END FUNCTION vect_sub
REAL FUNCTION vect_dot (a , b )
IMPLICIT NONE
REAL, INTENT(IN) :: a, b
vect_dot % x = a % x * b % x
vect_dot % y = a % y * b % y
vect_dot % z = a % z * b % z
END FUNCTION vect_dot
TYPE ( myvector ) FUNCTION vect_cross (a , b )
IMPLICIT NONE
TYPE ( myvector ) , INTENT (IN) :: a , b
vect_cross % x = (a % x * b % y) - (b % x * a % y)
vect_cross % y = (a % y * b % z) - (b % y * a % z)
vect_cross % z = (a % z + b % x) - (a % x * b % z)
END FUNCTION vect_cross
end program assign_9_2
当我编译它时,我收到一条错误消息:错误:
assign_9_2.f90:42.1:
vect_dot%x =(a%x * b%x) 1 错误:(1)处的不可分类陈述 assign_9_2.f90:43.1:
vect_dot%y =(a%y * b%y) 1 错误:(1)处的不可分类陈述 assign_9_2.f90:44.1:
vect_dot%z =(a%z * b%z) 1 错误:(1)
处的不可分类陈述有人可以帮我知道我哪里出错了谢谢你。
答案 0 :(得分:0)
您的功能vect_dot
为REAL
而非TYPE(my_vect)
,参数a
和b
也是如此。