I have a function which I want to do some mathematical operations inside of it, on an array which I will input to it as an array, and then the function will return an array as the output. This is the code I've been trying out but I can't seem to get it working!
program solve_linear
implicit none
real, allocatable :: A( :,: ) ,B(:),XX(:)
integer :: M
real, allocatable :: X(:)
M=3
allocate(B(M),XX(M),X(1:M))
B(1)=7
B(2)=4
B(3)=-10
XX=X(B,M)
end program solve_linear
function X(B,M)
implicit none
integer, intent(in) :: M
real, dimension(M), intent(in) :: B
real, dimension(M) :: X
integer :: i
do i=1,M
X(i)=B(i)**2
end do
end function
My main problem is using the output of the function in my program code, which you can see in the XX=X(B,M). What I want to do here, is that I want a function that gets the array B as the input, and multiplies each array element by itself and returning the resulting array as the output of the function. So how can I achieve this?