Obscure vector function translation from fortran

조회 수: 1 (최근 30일)
David Winthrop
David Winthrop 2019년 7월 11일
답변: Walter Roberson 2019년 7월 11일
I have been tasked with translating some code into MATLAB. I am puzzled at this function. It is from a FEA software called ANSYS, and the only documentation is shown in the image below. I am having trouble figuring out what exactly this function does. Anyone ever heard of this before? It looks like the input argument inc1 just tells the function the number of rows in the vector, and similarly for inc2. Then the input argument n tells the number of columns (are we talking about vectors or arrays??) What is going on here?
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2019년 7월 11일
dot( v1(1:inc1:inc1*(n-1)),...
v2(1:inc2:inc2*(n-1)))
This matlab rendition creates temporary index vectors and creates temporary vectors of extracted elements. That works OK, but is not as efficient at the low level as compiled code along the lines of
Off1=1
Off2=1
Result = 0
for k=1:n
Result = Result + v1(Off1) * v2(off2)
Off1 = Off1 + inc1
Off2 = Off2 + inc2
end
Now let us consider
A * B %matrix multiply
That involves a whole series of
dot( A(:, k), B(k, :) )
Which is vidot(&A(1,k),1,&B(k,1),size(B,1),size(A,1))
Where here & is intended to indicate "address of"
You could implement a matrix multiply with a lot of temporary index vectors and temporary extraction of vectors, but that involves a lot of temporary operations and storage management that you can see are not needed if you know the distance between vector elements.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by