Created
September 15, 2016 21:01
-
-
Save aron-bordin/96ec7c8f897b901c848007ee2c5f45a5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<h2 class="page-header">Linear Systems (A⋅x = b)</h2> | |
<div class="alert alert-warning" ng-if="error != null"> | |
<strong>Error</strong> {{error}} | |
</div> | |
<form class="form-horizontal"> | |
<div class="form-group"> | |
<label for="txtinput" class="col-sm-2 control-label">Method</label> | |
<div class="col-sm-10"> | |
<select class="form-control" ng-model="linear.method"> | |
<optgroup label="Direct"> | |
<option value="gauss">Gauss</option> | |
<option value="gausspivot">Gauss - Parcial Pivoting</option> | |
<option value="gausspivottotal">Gauss - Total Pivoting</option> | |
<option value="gausscompact">Gauss - Compact</option> | |
<option value="lu">LU-decomposition</option> | |
<option value="cholesky">Cholesky</option> | |
</optgroup> | |
<optgroup label="Iterative"> | |
<option value="jacobi">Jacobi-Richardson</option> | |
<option value="seidel">Gauss-Seidel</option> | |
</optgroup> | |
</select> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="txtinput" class="col-sm-2 control-label">Nº variables</label> | |
<div class="col-sm-10"> | |
<input type="number" ng-model="linear.dimension" ng-change="updateDimension(linear.dimension)" class="form-control" placeholder="Number of variables"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="txtinput" class="col-sm-2 control-label">A</label> | |
<div class="col-sm-10"> | |
<table class="table linear" ng-table="LinearCtrl.tableParams"> | |
<caption>Insert the matrix A data.</caption> | |
<thead> | |
<tr> | |
<th>#</th> | |
<th ng-repeat="i in repeater(linear.dimension)">X<sub>{{i}}</sub></th> | |
<th>b</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr ng-repeat="(l, line) in linear.data track by $index"> | |
<td ng-repeat="(key, item) in line track by $index"> | |
<div ng-if="key == 0" scope="row" >L<sub>{{item}}</sub></div> | |
<div ng-if="key != 0"> | |
<input type="text" ng-model="linear.data[l][key]" class="form-control"> | |
</div> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="col-sm-10 control-label"></label> | |
<div class="col-sm-2"> | |
<button type="button" class="btn btn-primary" tabindex="-1" ng-click="do_linear(linear)" > | |
Solve | |
</button> | |
</div> | |
</div> | |
<div class="alert alert-success" ng-if="result != null"> | |
<strong>X: [{{(result || []).join(', ')}}]</strong> | |
</div> | |
</form> |
This file contains hidden or 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
numericalApp.controller('LinearCtrl', ['$scope', '$http', 'NgTableParams', | |
function ($scope, $http, NgTableParams) { | |
$scope.linear = {'method': 'gauss', 'dimension': 3, 'data': null}; | |
$scope.error = null; | |
$scope.result = null; | |
$scope.repeater = function (range) { | |
var arr = []; | |
for (var i = 1; i <= range; i++) | |
arr.push(i); | |
return arr; | |
}; | |
$scope.updateDimension = function (d) { | |
var data = []; | |
for (var k = 0; k < d; k++) { | |
var obj = []; | |
for (var i = 0; i <= d + 1; i++) { | |
if (i == 0) { | |
obj.push(k + 1); | |
} else { | |
obj.push(1); | |
} | |
} | |
data.push(obj); | |
} | |
$scope.linear.data = data; | |
}; | |
$scope.updateDimension(3); | |
this.tableParams = new NgTableParams({}, {dataset: $scope.linear.data}); | |
$scope.do_linear = function (linear) { | |
console.log(linear); | |
$scope.error = null; | |
$scope.result = null; | |
$http.post(URL_LINEAR, JSON.stringify(linear)). | |
success(function(data) { | |
console.log(data); | |
$scope.error = null; | |
if(data.status == 'OK') { | |
$scope.result = data.data; | |
} else { | |
$scope.error = data.info; | |
} | |
}). | |
error(function(data) { | |
$scope.error = data ? data.info : 'Unexpected error'; | |
}); | |
} | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment