

In addition to Dot and Cross the spreadsheet contains the following vector related functions (optional function arguments are shown in italics): Note that if these functions are to be used direct from the spreadsheet they must be called through the Dot or Cross functions, which will peform the necessary conversion of the spreadsheet range into a 1D array of doubles. The GetVect function is used in the Dot and Cross functions, which in turn call Dot2, Dot3, Cross2 or Cross3 as appropriate. Note that the function returns the size of the array Vect2, but because Vect2 was passed as an empty double array “by reference”, its contents are available to the calling procedure.

If Vect1 has 2 dimensions, check the orientation, assuming “vertical” if it has two or more rows, or “horizontal” if it has 1 row.Find the number of dimensions of Vect1 (calling the NumDims function).Find the size of the first dimension in Vect1.If the input vector (Vect1) is a range, convert it into a Variant array.If TypeName(Vect1) = "Range" Then Vect1 = Vect1.Value2

Excel vector code code#
That is what the code below does:įunction GetVect(Vect1 As Variant, ByRef Vect2() As Double) As Variant horizontal or vertical spreadsheet ranges, or 1D or 2D arrays of doubles or variants) into a uniform format for processing by the vector functions with minimum overhead. The first step was to write a routine to convert different input types (i.e.
Excel vector code download#
Several of their vector related functions have been converted to VBA and are included in the download spreadsheet. In the course of researching this post I came across the Softsurfer site, which contains detailed descriptions of coordinate geometry related algorithms, including c++ code. In the following post I will have a closer look at the application of vector methods to calculating areas and other geometric section properties. Refer to Using Array Formulas if you are not familiar with their use. Many of the UDFs in this spreadsheet return results as an array function.
Excel vector code full#
The VectorFunc.xlsb spreadsheet includes full open source code for all the functions. It’s easily fixed with some User Defined Functions (UDFs) of course, so that is what this post examines. This is a strange omission, even by Microsoft standards, considering that they have gone to the trouble of programming several esoteric mathematical functions such as the Bessel Function, but they haven’t provided the most basic support for operations on vectors. =SUMPRODUCT() (Equivalent to the vector dot product) I am using the right "format" for how he wants us to do it, (if i do something that works, but don't format it the way he likes i don't get credit.) the row vector is reading properly in the variable explorer, but i am only getting a 2x2 column vector (with the first column being the 0th column and being all zeros, again how he wants it), I havent even gotten to the multiplication part of the code because i cant get python to read the column vector correctly.The comments from Bill Harvey in the previous post prompted me to have a closer look at the functions available in Excel for working with vectors. the row vector is from cells A1-C1, and the column vector is from cells A3-A5 in my excel spreadsheet. my professor is making us multiply a 1X3 row vector by a 3x1 column vector, and i cant get python to read the column vector. OK i think this must be a super simple thing to do, but i keep getting index error messages no matter how i try to format this.
