Jump to content
Sign in to follow this  
Andreik

Forecast Function Help

Recommended Posts

Andreik

I think most have used FORECAST function from MS Excel.

How can I write this function in AutoIt?

My problem is how can I compute the value of a?

Any idea is welcome.

Here is description of function from Excel:

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Andreik

To be honest I'm working on something similar myself, started two days ago, but with another algorithm. Take a look here and see if it helps. I found it pretty useful.

http://en.wikipedia.org/wiki/Regression_analysis

Is useful your link, but I don't know why the return value is not correct.

Here is my example:

Dim $TEST1[6]
$TEST1[0] = 5; Index of array
$TEST1[1] = 6
$TEST1[2] = 7
$TEST1[3] = 9
$TEST1[4] = 15
$TEST1[5] = 21

Dim $TEST2[6]
$TEST2[0] = 5; Index of array
$TEST2[1] = 20
$TEST2[2] = 28
$TEST2[3] = 31
$TEST2[4] = 38
$TEST2[5] = 40

Func ArrayAverage($Array)
    Local $Sum = 0
    For $Index = 1 To $Array[0]
        $Sum += $Array[$Index]
    Next
    Return $Sum/$Array[0]
EndFunc

Func FORECAST($NUM,$Array1,$Array2)
    If Not IsNumber($NUM) Then Return "#VALUE!"
    If UBound($Array1) <> UBound($Array2) Then Return "#N/A"
    If Not IsArray($Array1) And Not IsArray($Array2) Then Return "#DIV/0!"
    Local $PSum = 0 , $Sum = 0
    Local $XAvg = ArrayAverage($Array1)
    Local $YAvg = ArrayAverage($Array2)
    For $Index = 1 To $Array1[0]
        $PSum += ($Array1[$Index]-$XAvg)*($Array2[$Index]-$YAvg)
        $Sum += ($Array1[$Index]-$XAvg)^2
    Next
    Local $b = $PSum/$Sum
    Local $a = $XAvg - $b*$YAvg
    Return $a+$b*$NUM
EndFunc
MsgBox(0,"FORECAST",FORECAST(30,$TEST1,$TEST2))
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×