#Include "crt.bi" 'for rounding only Type vector Dim As Double element(Any) End Type Type matrix Dim As Double element(Any,Any) Declare Function inverse() As matrix Declare Function transpose() As matrix private: Declare Function GaussJordan(As vector) As vector End Type 'mult operators Operator *(m1 As matrix,m2 As matrix) As matrix Dim rows As Integer=Ubound(m1.element,1) Dim columns As Integer=Ubound(m2.element,2) If Ubound(m1.element,2)<>Ubound(m2.element,1) Then Print "Can't do" Exit Operator End If Dim As matrix ans Redim ans.element(rows,columns) Dim rxc As Double For r As Integer=1 To rows For c As Integer=1 To columns rxc=0 For k As Integer = 1 To Ubound(m1.element,2) rxc=rxc+m1.element(r,k)*m2.element(k,c) Next k ans.element(r,c)=rxc Next c Next r Operator= ans End Operator Operator *(m1 As matrix,m2 As vector) As vector Dim rows As Integer=Ubound(m1.element,1) Dim columns As Integer=Ubound(m2.element,2) If Ubound(m1.element,2)<>Ubound(m2.element) Then Print "Can't do" Exit Operator End If Dim As vector ans Redim ans.element(rows) Dim rxc As Double For r As Integer=1 To rows rxc=0 For k As Integer = 1 To Ubound(m1.element,2) rxc=rxc+m1.element(r,k)*m2.element(k) Next k ans.element(r)=rxc Next r Operator= ans End Operator Function matrix.transpose() As matrix Dim As matrix b Redim b.element(1 To Ubound(this.element,2),1 To Ubound(this.element,1)) For i As Long=1 To Ubound(this.element,1) For j As Long=1 To Ubound(this.element,2) b.element(j,i)=this.element(i,j) Next Next Return b End Function Function matrix.GaussJordan(rhs As vector) As vector Dim As Integer n=Ubound(rhs.element) Dim As vector ans=rhs,r=rhs Dim As matrix b=This #macro pivot(num) For p1 As Integer = num To n - 1 For p2 As Integer = p1 + 1 To n If Abs(b.element(p1,num))30 Then precision=30 Dim As zstring * 40 z:Var s="%." &str(Abs(precision)) &"f" sprintf(z,s,x) If Val(z) Then Return Rtrim(Rtrim(z,"0"),".")Else Return "0" End Function Function show(a() As Double,places as long=10) As String Dim As String s,g For n As Long=Lbound(a) To Ubound(a) If n<3 Then g="" Else g="^"+Str(n-1) if val(cround(a(n),places))<>0 then s+= Iif(Sgn(a(n))>=0,"+","")+cround(a(n),places)+ Iif(n=Lbound(a),"","*x"+g)+" " end if Next n Return s End Function dim as double x(1 to ...)={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} dim as double y(1 to ...)={1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321} Redim As Double ans() regress(x(),y(),ans(),3) print show(ans()) sleep