Post by bluatigro on Apr 2, 2020 8:50:27 GMT
if you want more calculations change first line to :
dim a( n , n + 1 ) , c( n )
dim a( n , n + 1 ) , c( n )
dim a( 10 , 11 ) , c( 10 )
[070] print "*** set liniar calculations solver . ***"
[090] input "how many calculations ? [ 0 ... 10 ] : " ; in$
[100] x = val( in$ )
[110] if x < 0 or x > 10 then goto [090]
[130] for i = 1 to x
cls
[140] print "calcuation "; i
[150] for j = 1 to x
[160] print "coeficent " ; i ; "-" ; j
[170] input in$
a( i , j ) = val( in$ )
[180] next j
[190] print "const " ; i
[200] input in$
a( i , x + 1 ) = val( in$ )
[210] print
[220] next i
'' calc
[240] for j = 1 to x - 1
[250] for i = j + 1 to x
'' seartch for highest in colom
[270] p = 0
[280] g = abs( a( i , j ) )
[290] for q = j to x
[300] if g >= abs( a( q , j ) ) then goto [330]
[310] p = q
[320] g = abs( a( q , j ) )
[330] next q
'' swap row
[340] if p = 0 then goto [420]
[360] for q = 1 to x + 1
[370] a = a( j , q )
[380] a( j , q ) = a( p , q )
[390] a( p , q ) = a
[400] next q
'' sweep coeficents
[420] if a( j , j ) = 0 then goto [570]
[430] if a( i , j ) = 0 then goto [570]
[440] f = -1 * a( i , j ) / a( j , j )
[450] t = 0
'' sweep
[470] for y = 1 to x + 1
[480] a( i , y ) = a( i , y ) + a( j , y ) * f
[490] if abs( a( i , y ) ) > 1e-5 then goto [530]
[500] a( i , y ) = 0
[510] if ( y > x ) or ( a( i , y ) <> 0 ) then goto [530]
[520] t = t + 1
[530] next y
[540] if t < x then goto [570]
[550] i = x + 1
[560] j = x
[570] next i
[580] next j
[590] if t = x then goto [790]
'' sub
[610] for i = x to 1 step -1
[620] z = a( i , x + 1 )
[630] if i = x then goto [670]
[640] for y = i + 1 to x
[650] z = z - a( i , y ) * c( y )
[660] next y
[670] if a( i , i ) = 0 then goto [790]
[680] c( i ) = z / a( i , i )
[690] next i
'' output
[710] cls
[720] print "*** set of calcuations ***"
[730] print "gauss sweep"
[740] print
[750] for i = 1 to x
[760] print "coeficient " ; i ; " = " ; c( i )
[770] next i
[780] goto [800]
[790] print "no solution !!"
[800] print "[ end gauss sweep ]"