Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with 1 x 2 array output

This shouldn't be hard for the excel experts.

here's my code:

Function RandNormCorr(mean1, sd1, mean2, sd2, corr)
'returns two random numbers that are based on different distributions
'and has a certain correlation

Dim xymat(1, 2) As Variant 'output array
Dim z1 As Variant
Dim z2 As Variant

z1 = gauss 'gauss is a random number generation function
z2 = gauss

x = z1 * Sqr((1 + corr) / 2) + z2 * Sqr((1 - corr) / 2)
y = z1 * Sqr((1 + corr) / 2) - z2 * Sqr((1 - corr) / 2)

xymat(1, 1) = mean1 + x * sd1
xymat(1, 2) = mean2 + y * sd2

RandNormCorr = xymat


End Function

I want a (1,2) array to show:
mean1 + x * sd1 on the left cell and
mean2 + y * sd2 on the right cell

Of course I highlight a 1x2 range, type the function, the
ctrl+shift+enter

this is what comes out:
0 0
pressing f2 f9 will reveal this
={0,0,0;0,-0.926298991003733,-1.12127338720803}
={0,0,0;0,-1.57926241712754,-0.0663085926997917

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with 1 x 2 array output

Your output array should be defined as follows
Dim xymat(0, 1) As Varian
Then
xymat(0, 0) = mean1 + x * sd1
xymat(0, 1) = mean2 + y * sd
An
Range("Left cell address") = xymat
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with 1 x 2 array output

Oh yeah! that's because I did not indicate Option Base 1
Thanks! Need to get used to this

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Help with 1 x 2 array output

If you are returning a horizontal array to the worksheet, would this idea
work?

Function RandNormCorr(mean1, sd1, mean2, sd2, corr)
Dim z1 As Double 'Variant
Dim z2 As Double 'Variant
Dim x As Double
Dim y As Double

' gauss is a random number generation function
z1 = gauss
z2 = gauss

x = z1 * Sqr((1 + corr) / 2) + z2 * Sqr((1 - corr) / 2)
y = z1 * Sqr((1 + corr) / 2) - z2 * Sqr((1 - corr) / 2)
RandNormCorr = Array(mean1 + x * sd1, mean2 + y * sd2)
End Function


Just another version of your equation if I didn't make a mistake...

Function RandNormCorr(mean1, sd1, mean2, sd2, corr)
Dim z1 As Double
Dim z2 As Double
Dim x As Double
Dim y As Double

' gauss is a random number generation function
z1 = gauss
z2 = gauss

x = (Sqr(1 + corr) * z1 + Sqr(1 - corr) * z2) / Sqr(2)
y = x - z2 * Sqr(2 - 2 * corr)
RandNormCorr = Array(mean1 + x * sd1, mean2 + y * sd2)
End Function


--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"jomni " wrote in message
...
Oh yeah! that's because I did not indicate Option Base 1
Thanks! Need to get used to this.


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a List Output from a Horizontal Array Input Rob Excel Worksheet Functions 4 September 17th 09 05:40 PM
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
customise array formula output TUNGANA KURMA RAJU Excel Discussion (Misc queries) 0 October 25th 05 05:15 AM
Getting output from an excel output back to cscript.. J S Excel Programming 0 January 21st 04 09:06 PM


All times are GMT +1. The time now is 05:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"