Skip to content

Commit

Permalink
Updating stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
NateZimmer committed Mar 22, 2017
1 parent 65a486c commit aad0026
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 4 deletions.
31 changes: 29 additions & 2 deletions Maths.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,33 @@ function matrix_delete_column(A,colNum)
return M;
}


function matrixs_decimate(A,decNumber)
{
var M = [];
var deci = (decNumber ==0) ? 1 : decNumber;

for(var i = 0; i <A.length; i++)
{
if(i % decNumber == 0)
{
M.push(A[i])
}
}
return M;
}

matrix.prototype.decimate = function(decNumber)
{
var M = matrixs_decimate(this.value,decNumber);
return matrix.make(M);
};

matrix.decimate = function(A,decNumber)
{
return matrix.make(A).decimate(decNumber);
}

//Add to parent class
matrix.prototype.deleteRow = function(rowNum)
{
Expand Down Expand Up @@ -2688,7 +2715,7 @@ plotyLayout = {
};


var defaultScatterObj = {
defaultScatterObj = {
x :[],
y :[],
mode : 'markers',
Expand All @@ -2699,7 +2726,7 @@ var defaultScatterObj = {
}
}

var defaultLineObj = {
defaultLineObj = {
x :[],
y :[],
mode : 'lines',
Expand Down
63 changes: 63 additions & 0 deletions Matrixs/calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
MIT License (MIT)
Copyright (c) 2016 Nathan Zimmerman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

var matrix = require('./matrixs');

//Numerical Derivative
function matrix_difference(A)
{
var M = [];
for(var i = 1; i < A.length; i++)
{
M[i-1] = [];
M[i-1][0] = A[i][0] - A[i-1][0];
}
return M;
}


//Numerical Integral
function matrix_sum(A)
{
var M = [];
for(var i = 1; i < A.length; i++)
{
M[i-1] = [];
M[i-1][0] = A[i][0] + A[i-1][0];
}
return M;
}


//Add to parent class
matrix.prototype.differences = function()
{
var M = matrix_difference(this.value);
return matrix.make(M);
};

//Add to parent class
matrix.differences = function(A)
{
return matrix.make(A).differences();
}


//Add to parent class
matrix.prototype.sums = function()
{
var M = matrix_sum(this.value,lb,ub);
return matrix.make(M);
};


//Add to parent class
matrix.sums = function(A)
{
return matrix.make(A).sums();
}
27 changes: 27 additions & 0 deletions Matrixs/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ function matrix_delete_column(A,colNum)
return M;
}


function matrixs_decimate(A,decNumber)
{
var M = [];
var deci = (decNumber ==0) ? 1 : decNumber;

for(var i = 0; i <A.length; i++)
{
if(i % decNumber == 0)
{
M.push(A[i])
}
}
return M;
}

matrix.prototype.decimate = function(decNumber)
{
var M = matrixs_decimate(this.value,decNumber);
return matrix.make(M);
};

matrix.decimate = function(A,decNumber)
{
return matrix.make(A).decimate(decNumber);
}

//Add to parent class
matrix.prototype.deleteRow = function(rowNum)
{
Expand Down
4 changes: 2 additions & 2 deletions Plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ plotyLayout = {
};


var defaultScatterObj = {
defaultScatterObj = {
x :[],
y :[],
mode : 'markers',
Expand All @@ -59,7 +59,7 @@ var defaultScatterObj = {
}
}

var defaultLineObj = {
defaultLineObj = {
x :[],
y :[],
mode : 'lines',
Expand Down
121 changes: 121 additions & 0 deletions Poly/poly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@

Matrixs = require('./matrixs');

PolyLib = require('./poly');


function polyMultiply(polyOne,polyTwo)
{
var polyOneOrder = polyOne.length -1;
var polyTwoOrder = polyTwo.length -1;
var maxPolyOrder = polyTwoOrder + polyOneOrder;

var M = Matrixs.zeros(1,maxPolyOrder+1);
var temp = Matrixs.zeros(1,maxPolyOrder+1);

for(var i = 0; i < polyOne.length; i++)
{
for(var j = 0; j < polyTwo.length; j++)
{
temp.value[0][j+i] = polyOne[i]*polyTwo[j]
}
M = M.add(temp);
temp = temp.multiply(0);
}
return M.flatten();
}


function polyAdd(polyOne,polyTwo)
{
var poly1 = Matrixs.make(polyOne).flatten();
var poly2 = Matrixs.make(polyTwo).flatten();
var polyOneOrder = poly1.length;
var polyTwoOrder = poly2.length;
var maxPolyOrder = Math.max(polyOneOrder,polyTwoOrder);
var M = Matrixs.zeros(1,maxPolyOrder).flatten();

for(var i = 0 ; i < polyOneOrder; i++)
{
M[i] += poly1[i];
}
for(var i = 0 ; i < polyTwoOrder; i++)
{
M[i] += poly2[i];
}
return M;
}


function polyPow(polyOne,powVal)
{
var poly1 = Matrixs.make(polyOne).flatten();
var polyOneOrder = poly1.length;
var M = Matrixs.clone(poly1).flatten();
for(var i = 0; i < powVal - 1; i++)
{
M = polyMultiply(Matrixs.clone(M).flatten(),poly1)
}
return M;
}


function eulerDiffPoly(polyOne,timeStep)
{
var poly1 = Matrixs.make(polyOne).flatten();
var polyOneOrder = poly1.length;
var M = [poly1[0]];
for(var i = 1; i < polyOneOrder; i++)
{
var temp = polyMultiply([-1,1],[timeStep]);
var power = polyPow(temp,i);
var final = polyMultiply(power,[poly1[i]]);
M = polyAdd(Matrixs.clone(M).flatten(),final);
}
console.log('wtf');
return M;
}



function tf(numerator,denominator,type,timeStep,obj)
{
this.numerator = Matrixs.make(numerator).flatten();
this.numOrder = this.numerator.length;
this.denominator = Matrixs.make(denominator).flatten();
this.denOrder = this.denominator.length;

this.type = type;
this.timeStep = timeStep;
var icDefined = false;
if(typeof(obj) !='undefined')
{
if((typeof(obj.numIc) !='undefined') && (typeof(obj.denIc) !='undefined') )
{
icDefined = true;
this.numIc = Matrixs.make(obj.numIc).flatten();
this.denIc = Matrixs.make(obj.denIc).flatten();
}
}
if(!icDefined)
{
this.numIc = Matrixs.zeros(this.numOrder).flatten();
this.denIc = Matrixs.zeros(this.denOrder).flatten();
}

console.log('new TF Made!');
}

function calculateTf(tf,value)
{

return
}






PolyLib.poly

Empty file added Poly/polyLib.js
Empty file.
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>

<head>

</head>

<body>
<h1>Hello World!</h1>

<div id='plotDiv' style='margin:auto; width:700px;height:400px;background-color:#DDD;'></div>

</body>

<script src='plotly.min.js'></script>
<script src='Maths.js'></script>

</html>

0 comments on commit aad0026

Please sign in to comment.