Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Linear Regression


Does anyone have a good Linear Regression algorithm? I'm converting an old BASIC program to VB6 and this is what was in the origional:

VB Code:
'---------------------------------------------------'Rem POLYNOMIAL REGRESSION SUBROUTINE'Rem INPUTS D-DEGREE OF EQUATION, N-NUMBER OF POINTS'Rem OUTPUT C(D,COEFFICIENT DEGREE)-COEFFICIENT MATRIX'-------------------------------------------------Public Sub Poly_Regression(D As Integer, n As Integer) Dim A(13) As DoubleDim R(7, 8) As DoubleDim T(8) As DoubleDim k As Integer A(1) = n For i = 1 To n    x = x(i)    y = y(i)     For j = 2 To 2 * D + 1        A(j) = A(j) + x ^ (j - 1)    Next j     For k = 1 To D + 1        R(k, D + 2) = T(k) + y * x ^ (k - 1)        T(k) = T(k) + y * x ^ (k - 1)    Next k     T(D + 2) = T(D + 2) + y ^ 2Next i For j = 1 To D + 1    For k = 1 To D + 1        R(j, k) = A(j + k - 1)    Next kNext j For j = 1 To D + 1    k = j     For i = 1 To D + 2        S = R(j, i)        R(j, i) = R(k, i)        R(k, i) = S    Next i    Z = 1 / R(j, j)     For i = 1 To D + 2        R(j, i) = Z * R(j, i)    Next i     For k = 1 To D + 1        If k = j Then GoTo 1230            Z = -R(k, j)        For i = 1 To D + 2            R(k, i) = R(k, i) + Z * R(j, i)        Next i    Next kNext j C(D, 0) = R(1, D + 2)For j = 1 To D    C(D, j) = R(j + 1, D + 2)Next j End Sub


It's slightly archaic and without looking up linear regression on my own yet, I was wondering if someone had a pre-fab routine that was maybe a little more understandable if not shorter. ?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Linear Regression?
I'm reamaking an old game that I used to play called Star Fleet partly to build up my VB skills and because I should be fun!

I'm having troubles in the sector screen, it is a 10 x 10 matrix, the player can be in any cell and up to 5 torpedoes can be fired at any angle at the enemy. In order to follow a line to the target should I use linear regression and try to stay as close to the line as I can?

I tried to do some code already but it didn't work perfectly. I'll post it to see if anyone can spot my mistake.


Code:
Private Sub FireTorps(NumTorps As Integer)
Dim CountX As Integer
Dim CountY As Integer
Dim Count As Integer
Dim DistanceX(5) As Integer
Dim DistanceY(5) As Integer
Dim DiffX(5) As Single
Dim DiffY(5) As Single
Dim DistX(5) As Single
Dim DistY(5) As Single

Debug.Print "New torps"
Debug.Print "Player at " & Player.Sector.X & "," & Player.Sector.Y
Debug.Print "Torp #1 Destination" & Player.Torps(1).X & "," & Player.Torps(1).Y
Debug.Print "Torp #2 Destination" & Player.Torps(2).X & "," & Player.Torps(2).Y

For CountX = 1 To NumTorps
With Player.Torps(CountX)
DistanceX(CountX) = Player.Sector.X - .X
If DistanceX(CountX) <> 0 Then
DistX(CountX) = 1 / DistanceX(CountX)
Else
DistX(Count) = 0
End If
DistanceY(CountX) = Player.Sector.Y - .Y
If DistanceY(CountX) <> 0 Then
DistY(CountX) = 1 / DistanceY(CountX)
Else
DistY(Count) = 0
End If
Debug.Print "Torp#" & CountX & "Distance X=" & DistanceX(1) & " Diff X=" & DistX(1)
Debug.Print "Torp#" & CountX & "Distance Y=" & DistanceY(2) & " Diff Y=" & DistY(2)
.X = Player.Sector.X
.Y = Player.Sector.Y
DiffX(CountX) = .X
DiffY(CountX) = .Y
'UpdateSRS
End With
Next CountX
Sem.TorpActive = True
Debug.Print vbCrLf

For CountX = 1 To 20
For Count = 1 To NumTorps
With Player.Torps(Count)
DiffX(Count) = DiffX(Count) - DistX(Count)
.X = DiffX(Count)
DiffY(Count) = DiffY(Count) - DistY(Count)
.Y = DiffY(Count)
Debug.Print "torp#" & Count & " x=" & .X & " y=" & .Y
End With
Next Count
UpdateSRS
Next CountX

Sem.TorpActive = False
End Sub

Thanks

Ron

Linear Regression
Hi was wondering if there was a way to use Excel to find the linear regression of a couple of points. I know the option is available in excel. But I do not know how to use them with VB6 ...

Any ideas ???

Problem With Linear Regression Code...
Hi there,

I have a Little problem with excel, In my job I have two computers, one with the Excel 2003 Version and the other with 2002 version, and I program in the first one... I Make a simple regression code in the first (2003) computer but it doesn't work in the 2002, sends me "error 1004 in execution time". my code is here:


Code:
Sub Macro2()

Application.Run "ATPVBAEN.XLA!Regress", ActiveSheet.Range("$B$6:$B$8847"), _
ActiveSheet.Range("$A$6:$A$8847"), False, False, , "", False, False, _
False, False, , False
End Sub

So I don't know if its an error of the version... and if is... how can I fixed it?.

Thanks in advance

Automating Regression
Can manually perform regression through data analysis tool pack, i.e. tools ... data analysis ... regression...

When attempting to record macro to automate the task was unable to do so.

Tried unsuccessfuly to edit macro.

Any help appreciated.

Mike D

Regression Automation
Does anybody know how to incorporate regression function linest or "ATPVBAEN.XLA!Regress" into the macro?
Thanks,
Alex

Power Regression
Hey,

i am writing a program that involves a lot of math regression equasions. I have got thru most of the equasions, but i am stuck on one.

y = c*e^(b*x)

I know that e = exp(1). X and Y are values that i plug into the equasion.

But how do i determine the values of C and B. I have searched the web for the last day and come up empty.

Thanks

Calculating R2 Regression Value
I am using a polynomial fit function class (Frank Schindler's ) found on the web. This unfortunately does not provide me with the r2 value. Does anyone have any polynomial/linear regression vb code that that does give r2. Or can someone give me an idea how r2 could be calculated.

Regression class as follows:-

Option Explicit

Private Const MaxO& = 25
Private GlobalO& '"Ordnung" = degree of the polynom expected
Private Finished As Boolean

Private SumX#(0 To 2 * MaxO)
Private SumYX#(0 To MaxO)
Private M#(0 To MaxO, 0 To MaxO + 1)
Private C#(0 To MaxO) 'coefficients in: Y = C(0)*X^0 + C(1)*X^1 + C(2)*X^2 + ...

Private Sub GaussSolve(O&)
'gauss algorithm implementation,
'following R.Sedgewick's "Algorithms in C", Addison-Wesley, with minor modifications
Dim i&, j&, k&, iMax&, T#, O1#
O1 = O + 1
'first triangulize the matrix
For i = 0 To O
iMax = i: T = Abs(M(iMax, i))
For j = i + 1 To O 'find the line with the largest absvalue in this row
If T < Abs(M(j, i)) Then iMax = j: T = Abs(M(iMax, i))
Next j
If i < iMax Then 'exchange the two lines
For k = i To O1
T = M(i, k)
M(i, k) = M(iMax, k)
M(iMax, k) = T
Next k
End If
For j = i + 1 To O 'scale all following lines to have a leading zero
T = M(j, i) / M(i, i)
M(j, i) = 0#
For k = i + 1 To O1
M(j, k) = M(j, k) - M(i, k) * T
Next k
Next j
Next i
'then substitute the coefficients
For j = O To 0 Step -1
T = M(j, O1)
For k = j + 1 To O
T = T - M(j, k) * C(k)
Next k
C(j) = T / M(j, j)
Next j
Finished = True
End Sub

Private Sub BuildMatrix(O&)
Dim i&, k&, O1&
O1 = O + 1
For i = 0 To O
For k = 0 To O
M(i, k) = SumX(i + k)
Next k
M(i, O1) = SumYX(i)
Next i
End Sub

Private Sub FinalizeMatrix(O&)
Dim i&, O1&
O1 = O + 1
For i = 0 To O
M(i, O1) = SumYX(i)
Next i
End Sub

Private Sub Solve()
Dim O&
O = GlobalO
If XYCount <= O Then O = XYCount - 1
If O < 0 Then Exit Sub
BuildMatrix O
On Error Resume Next
GaussSolve (O)
While (Err.Number <> 0) And (1 < O)
Err.Clear
C(0) = 0#
O = O - 1
FinalizeMatrix (O)
Wend
On Error GoTo 0
End Sub

Private Sub Class_Initialize()
Init
GlobalO = 2
End Sub

Public Sub Init()
Dim i&
Finished = False
For i = 0 To MaxO
SumX(i) = 0#
SumX(i + MaxO) = 0#
SumYX(i) = 0#
C(i) = 0#
Next i
End Sub

Public Property Get Coeff#(Exponent&)
Dim Ex&, O&
If Not Finished Then Solve
Ex = Abs(Exponent)
O = GlobalO
If XYCount <= O Then O = XYCount - 1
If O < Ex Then Coeff = 0# Else Coeff = C(Ex)
End Property

Public Property Get Degree&()
Degree = GlobalO
End Property
Public Property Let Degree(NewVal&)
If NewVal < 0 Or MaxO < NewVal Then
Err.Raise 6000, "RegressionObject", NewVal & " is an invalid property value! Use 0<= Degree <= " & MaxO
Exit Property
End If
Init
GlobalO = NewVal
End Property

Public Property Get XYCount&()
XYCount = CLng(SumX(0))
End Property

Public Function XYAdd(ByVal NewX#, ByVal NewY#)
Dim i&, j&, TX#, Max2O&
Finished = False
Max2O = 2 * GlobalO
TX = 1#
SumX(0) = SumX(0) + 1
SumYX(0) = SumYX(0) + NewY
For i = 1 To GlobalO
TX = TX * NewX
SumX(i) = SumX(i) + TX
SumYX(i) = SumYX(i) + NewY * TX
Next i
For i = GlobalO + 1 To Max2O
TX = TX * NewX
SumX(i) = SumX(i) + TX
Next i
End Function

Public Function RegVal#(X#)
Dim i&, O&
If Not Finished Then Solve
RegVal = 0#
O = GlobalO
If XYCount <= O Then O = XYCount - 1
For i = 0 To O
RegVal = RegVal + C(i) * X ^ i
Next i
End Function

Multiple Regression
i have a list of stock NAV and a set of 3 indices ie maket benchmarks....

i would like to run a multiple regression on this data ...

does anyone know how to do that using a macro in vb in excel.....

can some one pls may be fwd me to a site where i can find the code or ...may eb some one help me with the code...

thanks

MSChart Regression Property
I have a chart with 3 series, C1 C2 & C3. I can set the regression property for each of the 3 series at design-time, but how do I do this at run-time?

Cheers,
Rich.

Quadratic Regression Program
Can anyone point me to some free-ware that will allow me to perform quadratic regressions in VB? That is, the program should accept a series of X,Y data points and spit out the A,B,C values for the quadratic function that best fits the data (Y = AX^2+BX+C).

Thanks...

Multiple Regression Lines On Same Chart
Below is part of a macro that I recorded to place a chart on the active sheet and add three series of lines on the same chart;


Code:
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R6C4:R8C4"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R6C5:R8C5"
ActiveChart.SeriesCollection(1).Name = "=""Name 1"""
ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R10C4:R12C4"
ActiveChart.SeriesCollection(2).Values = "=Sheet1!R10C5:R12C5"
ActiveChart.SeriesCollection(2).Name = "=""Name 2"""
ActiveChart.SeriesCollection(3).XValues = "=Sheet1!R14C4:R16C4"
ActiveChart.SeriesCollection(3).Values = "=Sheet1!R14C5:R16C5"
ActiveChart.SeriesCollection(3).Name = "=""Name 3"""

I would like, if possible to change this code to automatically add any number of lines to the chart. I tried a For... Next statement where I substituted a variable, e.g. N in the following lines:


Code:
ActiveChart.SeriesCollection(N).XValues = "=Sheet1!R6C4:R8C4"
ActiveChart.SeriesCollection(N).Values = "=Sheet1!R6C5:R8C5"
ActiveChart.SeriesCollection(N).Name = "=""Name 1"""

This did not work since ActiveChart.SeriesCollection(N)... is not an array. I also realize that the Names of each series would have to be different as well and I would have to change the row and column locations through each pass of the loop.

Any way around this dilemma?

Regression Analysis In Excel Using Visual Basic 6.0
Hello guys, i am new member of this group. i have a question for u guys. i am developing a vb 6 application which requires Regression Analysis. I am suppossed to perform regression analysis on the data which is available in the excel sheet. the regression analysis is for one column against all the columns in the worksheet. There is a built-in tool in excel but that supports independent columns upto 16 variables but i want variables upto 150-200 variables.

i have got the tool called "Stat Tools ver 1.0 (palisade corporation)" which will work for any number of variables, also can be accessed from visual basic reference. But, i am unable to create the object of the class StatTool. if anyone knows this or any other tool for the above problem please tell me as i have a deadline to meet.

thanks in advance

regards,
S.ShivaKumar

Bar/Pie/Linear
Hello Everybody.... I am looking for some tutorial on Pie, Bar, and Linear graph at {B}{U} RUNTIME {/B}{/U} Using simple trigeometry concept. Let me be clear on this one... I am trying to establish 'amination' at timer control inside the picture box which it would display pie, bar, or linear graph changing at its values following via connection with another porgram.
However, I have Visual Basic Blackbook with me, I have tried to find any information including it...and Yet I have not find anything. For you who have VBBB would you know which page would that be on?
Let me know if you know any tutorial including webaddress....


Thanks in Advance

Linear Equations
mmmmm. I don't know if it's the right category to post this, but here I go. I found on inet, part of the code to solve Simultaneous Linear Equations. Works great for me, but I'm programming for Palm with the MobileVB from Appforge (Add IN for VB 6.0, www.appforge.com). Some of these devices don't have keys at all. Everything is done with screen touch. The problem, to summerize, is that it takes a lot of time to enter the Equations, (matrix form), even with a little keyboard I made.
Actually, there's no problem at all, if the equation is organized:

2A + 3b -c = 3 --> Enter each coefficient
... .... .... (Rest of equations)

Trouble comes for:

A/2 + A/3 + 1.5 B + 5b/8 + c/7 = 15/7
... ... ...

See what I mean? So I have been looking for a way to enter in a field box
the whole equation, and have the program organize it and simplifies it.

Thanx!

Mu-law To Linear PCM Conversion
Does anyone have a sample function or know of a system function that can convert an 8-bit mu-law encoded audio sample to a 16-bit linear PCM sample?

I will be performing this operation in-line as I capture the audio.

thanks

DLL Or SDK {linear Programming}
can u give me a link where to find or download the dll use for linear programming. HELP pls

MORE POWER

Linear Equations
How would you program the program to understand a equation lets say containing one variable from a text box in vb6???

Linear Searching
I am quite new to VIsual Basic and i was wondering how i would go about writing the code for a linear search that would look through a database for a certain name e.g 'Matthew'. Thanks

Linear Search
bghgh hjjjh

I am quite new to Visual Basic, and i was wondering how i would write the code for a linear search that would look through a Access database for a certain name. Thanks

Linear Graph
hai everybody


I have one doubt reg graphs in vb.

Is it possible to have linear graph or financial graphs in vb using mschart control or any other graph controls.


Bcoz i am looking for a financial graph.Can anybody help me


Bye
Ramya

Linear Search
Hi..i'm trying to make a program that will be given 2 list of numbers..they are to be sorted and then a 3rd list is a combination of the 2..i think i got the first part right..but i help on how to make it so that the 3rd list will contain numbers from the first two list..and get rid of any duplicate numbers..here is my code..check it out and reply back a.s.a.p on whut i could do or if i need to make changes on anything...! thanks

Dim list1() As Integer
Dim list2() As Integer
Dim Number As Integer
Dim index As Integer
Dim index2 As Integer
Dim i As Integer
Dim x As Integer

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdSearch_Click()
If txtlist1.Text = "" Or txtlist2.Text = "" Then
MsgBox "Please specify 2 list to search from!"
Else
picOutput.Cls
picOutput2.Cls
picOutPut3.Cls
i = 0
index = 0
Call Counts(list1(), txtlist1.Text, i)
ReDim list1(i) As Integer
Call Place(list1(), txtlist1.Text)
Call Sort(list1(), txtlist1.Text)
For index = 0 To i
picOutput.Print list1(index)
Next index
x = 0
index = 0

Call Counts(list2(), txtlist2.Text, x)
ReDim list2(x) As Integer
Call Place(list2(), txtlist2.Text)
Call Sort(list2(), txtlist2.Text)
For index = 0 To x
picOutput2.Print list2(index)
Next index
End If
index = 0
index2 = 0
Open "a:stuck in the past's List.txt" For Output As #3
For index = 0 To i
Write #3, list1(index)
Next index
For index2 = 0 To x
Write #3, list2(index2)
Next index2
Close #3
Open "stuck in the past's List.txt" For Input As #1
Do Until EOF(1)
Input #1, Number
If txtSearch.Text = Number Then
MsgBox "number found"
End If
Loop
Close #1
End Sub
Public Function Newlist(ByRef Numarray1() As Integer, ByRef Numarray2() As Integer)
Open txtlist1.Text For Input As #1
Open txtlist2.Text For Input As #2
Do Until EOF(1)
Input #1, Number
Numarray1(index) = Number
index = index + 1
Loop
Do Until EOF(2)
Input #2, Number1
Numarray2(index2) = Number1
index2 = index2 + 1
Loop
Close #2
Close #1
End Function
Public Function Place(ByRef Numarray() As Integer, ByRef Path As String)
Open Path For Input As #2
Do While Not EOF(2)
Input #2, Number
Numarray(index) = Number
index = index + 1
Loop
Close #2
End Function
Public Function Sort(ByRef Numarray() As Integer, ByRef Path As String)
'open the file and read each entry into the array
For Item = LBound(Numarray) To UBound(Numarray)
For index = LBound(Numarray) To UBound(Numarray) - 1
If Numarray(index) &gt; Numarray(index + 1) Then
Temp = Numarray(index)
Numarray(index) = Numarray(index + 1)
Numarray(index + 1) = Temp
End If
Next index
Next Item
End Function
Public Function Counts(ByRef Numbarray() As Integer, ByRef Paths As String, ByRef i As Integer)
'open the file and count how many entries there are
Open Paths For Input As #1
Do While Not EOF(1)
Input #1, Number
i = i + 1
Loop
Close #1
i = i - 1
End Function

Linear Search
Okay i'm trying to make a program that will be given 2 list of numbers..they are to be sorted and then a 3rd list is a combination of the 2..then u have to sort the 2 and go into linear search...okay heas my code tell me whut i'm doing wrong...
Dim list1(), list2() As Integer
Dim Number As Integer
Dim index As Integer
Dim i As Integer

Private Sub cmdsort_Click()
Open txtlist1.Text For Input As #1
Do While Not EOF(1)
Input #1, Number
i = i + 1
Loop
Close #1
i = i - 1
ReDim list1(i) As Integer
Call Place(list1(), txtlist1.Text)
Call Sort(list1(), txtlist1.Text)
For index = 0 To i
picOutput.Print list1(index)
Next index
End Sub
Public Function Place(ByRef Numarray() As Integer, ByRef Path As String)
Open Path For Input As #3
Do While Not EOF(3)
Input #3, Number
Numarray(index) = Number
index = index + 1
Loop
End Function
Public Function Sort(ByRef Numarray() As Integer, ByRef Path As String)
'open the file and read each entry into the array
Open Path For Input As #2
Do While Not EOF(2)
Input #2, Number
Numarray(index) = Number
picOutput.Print Numarray(index) 'Prints out original list
index = index + 1
Loop
Close #2
For Item = LBound(Numarray) To UBound(Numarray)
For index = LBound(Numarray) To UBound(Numarray) - 1
If Numarray(index) &gt; Numarray(index + 1) Then
Temp = Numarray(index)
Numarray(index) = Numarray(index + 1)
Numarray(index + 1) = Temp
End If
Next index
Next Item
End Function
Public Function Counts(ByRef Numbarray() As Integer, ByRef Paths As String)
'open the file and count how many entries there are
Open Paths For Input As #1
Do While Not EOF(1)
Input #1, Number
i = i + 1
Loop
Close #1
i = i - 1
End Function

Linear Graphs
I am trying to find an ActiveX component to integrate into VB that will provide the resources for generating linear and logrithmic graphs, but am having difficulty finding anything that can be beneficial. Does anyone have any suggestions on where I can locate something like that?

Interpolation: The Non-linear Kind
heelllllllooooooo.
ok well, i wrote a function that linearly interpolates btwn 2 .x files. the problem is, that many of my interpolations are objects such as arms and legs, and linear interpolation doesn't work. what ends up happening is the meshes get slightly skewed betweenthe 1st and last frames, since they do not stay in the same relative position. i was wondering if there is a way to interpolate, but do it in more of a circular manner. so rather than go straight between the positions, it travels in an arc so that the vertices all stay the same distance apart and from the origin of the object. this seems like it would be difficult though, and also costly to the cpu. the reason im doing this rather than just using a rotation matrix is because i first constructed the model of a person, and then just exported each part seperately such that i can now load varieties of arm and leg animations independently rather than having to export all the possible arm and leg combinations. since i export them seperately, the arm is constructed where it should be in the x file, but unfortunately that is far from the origin, and when i rotate the x file it rotates on the origin, causing the arm to be drastically out of place.so i can either reexport all the x files after moving every single moving joint of the model to 0,0,0 and then translating them in the program (which would also make it much more difficult to do the animation, since i cant see how it would look in the program) or i need a new method to use other than the d3dveclerp function that doesnt linearly interpolate. or my final choice is to just ignore it and hope it looks ok, although i think that it may cause problems if there are objects in the characters hand, since the hand would move up or down the object making it look strange.

hopefully there is a built in function or some easy way to implement better looking interpolation

Best Way For Solving Linear Algebra?
I am creating a microsoft excel workbook and need to solve a series of coupled, linear equations. I'm used to programming in FORTRAN and using Matlab, and I typically use Excel just for holding data. Does anyone have any thoughts on the best way for solving a system of equations?

My thought was to use VBA and Excel; to create a macro that can then dump the results into the spreadsheet.

any thoughts?

Solving A Set Of Linear Equations
Hi all,

As part of an application Im writing I need to solve a set of linear equations. The equations are in the form:
Ax=b.
Where b is a vector of numbers x is the vector of unknowns and A is the matrix of coefficients.
The matrix A is big (may be 3000x3000), and spars. It is also close to singular but than is by the way.

As this is a classic problem Im sure some one has done this before and there is no need for me to do it all over.
Does any one know of a *.dll or any thing else I could use to solve the problem.

Linear And Circular Intrepolation
I am working on a VB app Interface to a 3 axis stepper motor cnc / cam project, Using the Perallel Port I am able to control the 3 motors steps and direction along with haveing 6 inputs from my circuit board. I am able to move xyz positions but the code I am using has to many error steps meaning the motors will either over or under position. I need to do Linear and Circular Interpolation calculations of curX, curY, newX, newY so I can position the motors without step loss / gain. But i have been trying to find a snipit of code / formula to do this with no avail. I would appricate some help.


Thanks In advance,
Jeremy

Generating Non-Linear Random Numbers
I need to create random data but not on a linear scale. For example, I want random data to show how many TVs are in a household. For this example the range I am working on is 1 to 11. I could use:

randomValue = Int(Rnd * 11) + 1

But I want the random results to be based on a percentage. For this example (see below), when I create my data, I want 4% of housholds to have 1 TV, 8% to have 2 TVs, 12% have 3% and so on...

14%
28%
312%
420%
523%
613%
711%
83%
93%
102%
111%

How can I generate this? There is probably already an example here for this, but I do not know what it is called to be able to search for it.

Thank you.

Dying While Trying To Do Linear Programming In Excel
Not sure exactly where this would go but I'm totally totally stumped trying to put together this linear programming model. So here's the idea, an airplane makes 4 stops on its way from the West Coast to the East Coast. At each stop, it can purchase fuel with each stop having different prices. Given constraints, we are to determine the optimal purchase of fuel at each station to minimize fuel cost (we cannot simply fill up to full where the gas is cheapest because the heavier the plane, the faster gas burns, which wastes money). This is under the assumption that we do not know how much fuel we started with or ended with in this loop. My problem is that my linear program keeps running into a circular reference, which is expected. I created a separate table to add an extra dimension to the problem but am clueless as to how to program it. Suggestions would be nice.... here's a picture of the tables I have so far (Any help would be much appreciated):

http://img.photobucket.com/albums/v1...006/fuelLp.jpg (with values)
http://img.photobucket.com/albums/v1...006/fuelLp.jpg (formula view)

Calculating System Of Linear Equations
Hi everyone. I have been working on a program to balance Chemistry Equations, what I have done is set up a system of linear equations in matrix form.

For an example, see the screenshot of some sample output from my program. I would like to know what is the best method to solve a system of linear equations.

The numbers in the table are the contents of my array, each number denotes how many elements are in that compound, each column is a different variable, and each row is already set equal to zero. Like for the first row in the picture an example equation would be 1*A + 0*B - 2*C - 0*D, each letter being the coefficient of each compound...sorry if I explained more than I had to.

Thanks for the help.

Adaptation Of Non-linear Fit ActiveX Control
Help me guys, I'm trying to run a non-linear approximation method in an ActiveX control to fit my matrix function, and I don't know where to start.
I found this http://fitting.datamaster2003.com/ ActiveX non-linear least-squares fitter, and I'd like to use it in my matrix function for solving optical transmission.
What I dont get, is how I can stuff my variables, and the function, into this fitter function. My function, I call it "R" has 3 Single variables, and an Array, it goes like this

Code:
Function Rpc(Lambda As Single, SubstIndex As Single, n As Single, FilmProperty As Variant)
ReDim R(1 To n), T(1 To n), X(1 To n), C(1 To n), S(1 To n) As Variant
AA = 1 / SubstIndex
BB = 1
CC = 1 / SubstIndex
For I = 1 To n
R(I) = FilmProperty(2 * I - 1)
T(I) = FilmProperty(2 * I)
X(I) = (2 * 3.141592654 * R(I) * T(I)) / Lambda
'CALCULATE SINE AND COSINE TERMS FOR MATRIX ELEMENTS
C(I) = Cos(X(I))
S(I) = Sin(X(I))
Next I
'SETUP MATRIX ELEMENTS
B11 = C(1)
B12 = S(1) / R(1)
B21 = S(1) * R(1)
B22 = B11
'CHECK FOR ONE FILM
If n = 1 Then GoTo 500
For I = 1 To n
C11 = C(I)
C12 = S(I) / R(I)
C21 = S(I) * R(I)
C22 = C11
A11 = B11 * C11 - B12 * C21 'C11
A12 = B11 * C12 + B12 * C22 'C12
A21 = B21 * C11 + B22 * C21 'C21
A22 = -B21 * C12 + B22 * C22 'C22
B11 = A11
B12 = A12
B21 = A21
B22 = A22
Next I
500 CA = (AA * B11 - B22) ^ 2 + (BB * B12 - CC * B21) ^ 2
CB = (AA * B11 + B22) ^ 2 + (BB * B12 + CC * B21) ^ 2
Rpc = (CA / CB)
End Function


the fitter code goes like this:

Code:
Public WithEvents Fitter As DMFitter
Public NumPoints ' number of points in the dataset

Private Function Fitter_OnGetLMFunction(ByVal X As Variant, ByVal Parameters As Variant) As Double
'p1+p2*cx+p3*cx^2+p4*cx^3+p5*sin(p6*cx)
Fitter_OnGetLMFunction = Parameters(0) + Parameters(1) * X + _
Parameters(2) * X ^ 2 + Parameters(3) * X ^ 3 + _
Parameters(4) * Sin(Parameters(5) * X)
End Function

Sub Fitter_OnProgress()
Dim I, X, Parameters
Workbooks(1).Worksheets(1).Cells(39, 7) = Fitter.Iterations
For I = 1 To NumPoints
X = Workbooks(1).Worksheets(2).Cells(I, 1) ' X in 1st column
Parameters = Fitter.Parameters
Workbooks(1).Worksheets(2).Cells(I, 3) = Fitter_OnGetLMFunction(X, Parameters)
Next
DoEvents ' refresh chart
End Sub

Private Sub FitCommandButton_Click()
Dim I, datasheet, X, Y, Parameters
Set datasheet = Workbooks(1).Worksheets(2)
ReDim X(1000)
ReDim Y(1000)
I = 1
While datasheet.Cells(I, 1) <> ""
X(I - 1) = datasheet.Cells(I, 1)
Y(I - 1) = datasheet.Cells(I, 2)
I = I + 1
Wend
ReDim Preserve X(I - 2)
ReDim Preserve Y(I - 2)
NumPoints = UBound(X) + 1 ' save to use in Fitter_OnProgress

ReDim Parameters(5)
For I = 0 To UBound(Parameters)
If Workbooks(1).Worksheets(1).Cells(34 + I, 4) <> "" Then
Parameters(I) = Workbooks(1).Worksheets(1).Cells(34 + I, 4)
Else
Parameters(I) = 1
End If
Next

Set Fitter = CreateObject("Fitter.DMFitter")
Fitter.X = X
Fitter.Y = Y
Fitter.Expression = -2 ' perform differentiation numerically
Fitter.ParamCount = 6
' Fitter.Parameters = Array(1, -1, -0.1, 0, 50, 0.192)
Fitter.Parameters = Parameters
Fitter.Sigmas = Array(0, 0, 0, 0, 0, 0)
Fitter.WeightType = 0
Fitter.Options = Array(0, 0.0000001, 0)
Fitter.Iterations = 60
If Fitter.LMFit Then
Workbooks(1).Worksheets(1).Cells(33, 4) = Fitter.Deviation
Parameters = Fitter.Parameters
For I = 0 To UBound(Parameters)
Workbooks(1).Worksheets(1).Cells(34 + I, 4) = Parameters(I)
Next
Else
MsgBox "Fitter error " & Fitter.ResultCode
End If
End Sub


from what I understand, i need to replace Fitter_OnGetLMFunction = ... with my code...but how can I do this, and have the fit still work?

also, the sample files include vbproj files, but I can't open them with VB6, what gives?

VB Codes For Linear Programming Models
I am a research student. I want to know about vb codes for linear programming models. Please send me vb codes of very simple example of linear model.

ex:

Maximize 25 XB + 30 XC
Subject to (1/200) XB + (1/140) XC ≤ 40
0 ≤ XB ≤ 6000
0 ≤ XC ≤ 4000

if anybody know to write vb codes for this example, please send me.
Thanks

Linear Interpolation For An Array Of Values
Hi,
If have an array MyArray(100) which has had values set for some (unknown number of) elements. All other elements are zero.
What I need to do is to perform a linear interpolation algorithm to populate the whole array.
Any suggestions for a fast algorithm would be appreciated.

Help! Logarithmic To Linear Graph Convresion
does anyone knows how to convert a logarithmic graph to a linear graph and vice versa.....
badly need it... thank you very much!

How To Plot A Linear Equation (or Quadratic) In VB
Does anyone know the command that is used to plot a line (say, y = x) or a quadratic (e.g. y=x^2)
in VB? Does a command exist? Are there any sites I can go to that will give me the code? Thanks

Copyright 2005-08 www.BigResource.com, All rights reserved