Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
sqr function in vba
Hi,
When I add sqr function to the below myFormula it doesn't work anymore. So, this works fine: Function MyFormula(Array1, Array2) As Variant With Application.WorksheetFunction MyFormula = .MMult(.Transpose(Array1), .MMult(Array2, Array1)) End With End Function This doesn't work MyFormula = Sqr(.MMult(.Transpose(Array1), .MMult(Array2, Array1))) Does anyone know what am I missing here? Much obliged Gabriel |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
sqr function in vba
Function Sqr(Number As Double) As Double
are you passing a Number as Double to the sqr function? -- Regards, Tom Ogilvy Gabriel wrote in message om... Hi, When I add sqr function to the below myFormula it doesn't work anymore. So, this works fine: Function MyFormula(Array1, Array2) As Variant With Application.WorksheetFunction MyFormula = .MMult(.Transpose(Array1), .MMult(Array2, Array1)) End With End Function This doesn't work MyFormula = Sqr(.MMult(.Transpose(Array1), .MMult(Array2, Array1))) Does anyone know what am I missing here? Much obliged Gabriel |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
sqr function in vba
Gabriel,
The MMult function does a matrix multiplication of two arrays and results in yet another matrix. You cannot take the square root of a matrix, only of a scalar number (like sqr(2) = 1.414...). -- Dennis Eisen |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
sqr function in vba
MMULT returns an array. When a function returns an array to a cell,
the first element is put in the cell. Sqr() however, takes a value, not an array, as an argument. If you want to take the square root of the array's first element, use MyFormula = Sqr( _ .MMult(.Transpose(Array1), .MMult(Array2, Array1))(1, 1)) In article , (Gabriel) wrote: Hi, When I add sqr function to the below myFormula it doesn't work anymore. So, this works fine: Function MyFormula(Array1, Array2) As Variant With Application.WorksheetFunction MyFormula = .MMult(.Transpose(Array1), .MMult(Array2, Array1)) End With End Function This doesn't work MyFormula = Sqr(.MMult(.Transpose(Array1), .MMult(Array2, Array1))) Does anyone know what am I missing here? Much obliged Gabriel |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
sqr function in vba
Gabriel,
This extends my previous response, in that because the MMult function returns a matrix (even if it's a 1 x 1 matrix), the sqr function cannot be used. The appropriate formula you want to use is to incorporate the SUMPRODUCT function, which when applied to two arrays results in a scalar (rather than a 1 x 1 matrix), for which the sqr function can be applied. -- Dennis Eisen |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel Data Validation/Lookup function does function correcty | Excel Worksheet Functions | |||
copy of excel file not showing formulal/function in the function b | Excel Discussion (Misc queries) | |||
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) | Excel Worksheet Functions | |||
Offset function with nested match function not finding host ss. | Excel Worksheet Functions | |||
User-Defined Function pre-empting Built-in Function? How to undo???? | Excel Programming |