Last active
June 22, 2022 18:21
-
-
Save Recoskie/0733fdd835a6e134bfc929072bbcf67e to your computer and use it in GitHub Desktop.
Solve irrational numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Matrix used to solve sets of numbers in x^n. | |
//This matrix can be enlarged to higher dimensional numbers past root of 5. | |
var SMat = [ | |
[01,0,0,0,0,0], | |
[05,1,0,0,0,0], | |
[10,4,1,0,0,0], | |
[10,6,3,1,0,0], | |
[05,4,3,2,1,0], | |
[01,1,1,1,1,1] | |
]; | |
//Calculate sums with the matrix. | |
function calc( v ) | |
{ | |
var m = [], o = [], sum = 0; | |
var s = SMat.length - v.length; | |
for( var i1 = s; i1 < SMat.length; i1++ ) | |
{ | |
m = SMat[i1]; | |
for( var i2 = s; i2 < m.length; i2++ ) | |
{ | |
sum += m[i2] * v[i2-s]; | |
} | |
o[i1-s] = sum; sum = 0; | |
} | |
return( o ); | |
} | |
//Reverse sums with the matrix. | |
function rcalc( v ) | |
{ | |
var m = [], o = [], sum = 0; | |
var s = SMat.length - v.length; | |
for( var i1 = s; i1 < SMat.length; i1++ ) | |
{ | |
m = SMat[i1]; sum = v[i1-s]; | |
for( var i2 = 0; i2 < o.length; i2++ ) | |
{ | |
sum -= m[i2+s] * o[i2]; | |
} | |
o[i1-s] = sum; | |
} | |
return( o ); | |
} | |
//Calculate each A part in number. | |
function calcA( v, n ) | |
{ | |
var r1 = [], r2 = []; | |
var o = [], a = -1; | |
for( var i = 0, c = true; i < n; i++ ) | |
{ | |
r2 = r1 = v; while( ( c && r2[r2.length-1] <= 0 ) || ( !c && r2[r2.length-1] >= 0 ) ) | |
{ | |
++a; r1 = r2; r2 = calc( r1 ); | |
} | |
o[i] = a; a = -1; c = !c; v = r1.reverse(); | |
if( (c ? -v[0] : v[0]) >= 0 ){ break; } | |
} | |
return( o ); | |
} | |
//Put the number together. | |
function calcNum( a ) | |
{ | |
var num = a[a.length-1]; | |
for( var i = a.length - 2; i >= 0; i-- ) | |
{ | |
num = a[i] + 1/num; | |
} | |
return( num ); | |
} | |
//Take the number apart. | |
function getParts( num, n ) | |
{ | |
var a = [], r = 0; | |
for( var i = 0; i < n; i++ ) | |
{ | |
a[a.length] = r = num & -1; num=1/(num-r); | |
} | |
return( a ); | |
} | |
//Create and solve number patterns. | |
//cube root 2 vector. | |
var vect = [1,0,0,-2]; | |
//cube root 2 vector to 12 parts. | |
var parts = calcA( vect, 12 ); | |
/*Some other calculations you can do. | |
vect = [1,0,0,0,0,-911]; root 5 of 911. | |
vect = [2,0,0,0,0,-911]; root 5 of 911÷2. | |
vect = [1,0,-23]; square root of 23. | |
vect = [1,0,0,0,-0.5]; root 4 of 0.5. | |
To go higher than the root of 5 you will | |
Have to expand the SMat matrix.*/ | |
//Put parts into number Value. | |
var val = calcNum( parts ); | |
//Display parts and number value. | |
alert( "parts = " + parts + "\r\nval = " + val + "" ); | |
//Take the number value apart to 12 parts. | |
var nParts = getParts( val, 12 ); | |
alert( "take val apart: " + val + "\r\nparts = " + nParts + "" ); | |
//When we take a number apart we can translate its parts back into its vector combination. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment