Firts of all thanks to people who built the fbmath library , I think is wonderfull.
I have made the following program in order to solve matrix operations.
SUMA,RESTA,MULTIPLICACION=Addition, Subtraction, Multiplication
It works ok but I get 3 blue warnings that I dont know how to avoid. I can solve it writing the word return 666 for example but the really return result is a matrix not an only number.
this is the code:
Code: Select all
#INCLUDE "fbmath.bi"
Function SUMA(MA() As Double,MB() As double) As Integer
If UBound (MA,1)<>UBound (MB,1) Then Print "NO SE PUEDEN SUMAR, LA MATRIZ ES A": Exit Function
If UBound (MA,2)<>UBound (MB,2) Then Print "NO SE PUEDEN SUMAR, LA MATRIZ ES A": Exit Function
Dim As Integer I,J
For I=1 To UBound (MA,1)
For J=1 To UBound (MA,2)
MA(I,J)=MA(I,J)+MB(I,J)
Next
Next
End Function
Function RESTA(MA() As Double,MB() As Double) As Integer
If UBound (MA,1)<>UBound (MB,1) Then Print "NO SE PUEDEN RESTAR, LA MATRIZ ES A": Exit Function
If UBound (MA,2)<>UBound (MB,2) Then Print "NO SE PUEDEN RESTAR, LA MATRIZ ES A": Exit Function
Dim As Integer I,J
For I=1 To UBound (MA,1)
For J=1 To UBound (MA,2)
MA(I,J)=MA(I,J)-MB(I,J)
Next
Next
End Function
Sub PINTAMATRIZ(MA() As Double)
Dim As Integer I,J
For I=1 To UBound (MA,1)
For J=1 To UBound (MA,2)
Print MA(I,J),
Next
Print ""
Next
End Sub
Function MULTIPLICA(MA() As Double,MB() As Double,MC()As Double) As Integer
Dim As Integer I,J,K,N,M,P
For I=1 To UBound(MA,1)
For J=1 To UBound(MB,2)
MC(I,J)=0
For K=1 To UBound(MA,2)
MC(I,J)=MC(I,J)+MA(I,K)*MB(K,J)
Next K
Next J
Next I
End Function
DIM AS DOUBLE Det ' Determinant
DIM AS INTEGER ErrCode ' Error code
Dim As Double A(1 To 3,1 To 2)= {{1,2},{2,2},{6,9}}
Dim As Double B(1 To 2,1 To 3)= {{1,1,8},{1,1,7}}
Dim As Double C(1 To 3,1 To 3)
Dim As Double D(1 To 3,1 To 3)= {{1,1,8},{1,1,7},{1,3,3}}
Print "MATRIZ A"
PINTAMATRIZ (A())
Print ""
Print "MATRIZ B"
PINTAMATRIZ (B())
Print ""
Print "MULTIPLICA"
Print ""
MULTIPLICA (A(),B(),C())
PINTAMATRIZ (C())
SUMA (A(),B())
Print "SUMA"
PINTAMATRIZ (A())
Print ""
RESTA (A(),B())
Print "RESTA"
PINTAMATRIZ (A())
Print ""
Sleep
Cls
PINTAMATRIZ (D())
Print ""
GaussJordan D(), Det
SELECT CASE MathErr
CASE MatOk
PINTAMATRIZ (D())
PRINT : PRINT "Determinant =", Det
Print ""
GaussJordan D(), Det
IF MathErr = MatOk THEN
PINTAMATRIZ (D())
END IF
CASE MatErrDim
PRINT "Non-compatible dimensions!"
CASE MatSing
PRINT "Quasi-singular matrix!"
END Select
Sleep
Make done
C:\Program Files (x86)\FreeBASIC\fbc -s console "SUBRUTINAS_MATRIZ.bas"
SUBRUTINAS_MATRIZ.bas(13) warning 14(0): Function result was not explicitly set
SUBRUTINAS_MATRIZ.bas(23) warning 14(0): Function result was not explicitly set
SUBRUTINAS_MATRIZ.bas(44) warning 14(0): Function result was not explicitly set
Thanks very much.