diff options
author | ASP1234 | 2016-06-23 06:09:00 +0000 |
---|---|---|
committer | ASP1234 | 2016-06-23 06:12:59 +0000 |
commit | faeb04600e13a5c1c4ca410cf65309d65e269b41 (patch) | |
tree | 2a1dcf2321735e2b67eeaf5d7991282274191d60 | |
parent | 20e581facb1871847e0fa945ccd3020a10e653c9 (diff) | |
download | xcos-on-web-faeb04600e13a5c1c4ca410cf65309d65e269b41.tar.gz xcos-on-web-faeb04600e13a5c1c4ca410cf65309d65e269b41.tar.bz2 xcos-on-web-faeb04600e13a5c1c4ca410cf65309d65e269b41.zip |
Implement BOUNCE Block
-rw-r--r-- | data_structures_correct/BOUNCE.js | 104 | ||||
-rw-r--r-- | details.js | 7 |
2 files changed, 66 insertions, 45 deletions
diff --git a/data_structures_correct/BOUNCE.js b/data_structures_correct/BOUNCE.js index 427b00a..78ccedc 100644 --- a/data_structures_correct/BOUNCE.js +++ b/data_structures_correct/BOUNCE.js @@ -1,50 +1,68 @@ function BOUNCE() { + BOUNCE.prototype.define = function BOUNCE() { + this.n = 2; - var n = 2; + this.k = 0; + this.ipar = []; - var k = 0; - var ipar=[]; - - for(var i=1; i<=n; i++) - { - for(var j=i+1; j<=n ;j++) - { - ipar[k]=[i]; - k++; - ipar[k]=[j]; - k++; + for (var i = 1; i <= this.n; i++) { + for (var j = i + 1; j <= this.n; j++) { + this.ipar[this.k] = [i]; + this.k++; + this.ipar[this.k] = [j]; + this.k++; + } } + + this.walls = [ + [0], + [5], + [0], + [5] + ]; + this.x1 = [ + [2], + [2.5] + ]; + this.xd = [ + [0], + [0] + ]; + this.y1 = [ + [3], + [5] + ]; + this.yd = [ + [0], + [0] + ]; + this.g = 9.81; + this.C = 0; + this.rpar1 = ones(this.n, 1); + this.rpar2 = this.rpar1; + this.state = [...math.transpose(this.x1), ...math.transpose(this.xd), ...math.transpose(this.y1), ...math.transpose(this.yd)]; + + var model = scicos_model(); + model.sim = list(new ScilabString(["bounce_ball"]), new ScilabDouble([4])); + model.in = new ScilabDouble(); + model.out = new ScilabDouble([this.n], [this.n]); + model.state = new ScilabDouble(...colon_operator(this.state)); + model.rpar = new ScilabDouble(...this.rpar1, ...this.rpar2, ...this.walls, [this.g], [this.C]); + model.ipar = new ScilabDouble(...this.ipar); + model.nzcross = new ScilabDouble([this.n * (this.n - 1) / 2 + 4 * this.n]); + model.blocktype = new ScilabString(["c"]); + model.dep_ut = new ScilabBoolean([false, true]); + + var exprs = new ScilabString([sci2exp(this.rpar1)], [sci2exp(this.rpar2)], [sci2exp(this.walls)], [sci2exp(this.x1)], [sci2exp(this.xd)], [sci2exp(this.y1)], [sci2exp(this.yd)]); + var gr_i = new ScilabString(["xstringb(orig(1),orig(2),\"BOUNCE\",sz(1),sz(2));"]); + this.x = new standard_define(new ScilabDouble([3, 2]), model, exprs, gr_i); + + return new BasicBlock(this.x); + } + + BOUNCE.prototype.details = function BOUNCE() { + + return this.x } - - var walls=[[0],[5],[0],[5]]; - var x=[[2],[2.5]]; - var xd=[[0],[0]]; - var y=[[3],[5]]; - var yd=[[0],[0]]; - var g=9.81; - var C=0; - var rpar1=ones(n,1); - var rpar2=rpar1; - var state=[x,xd,y,yd]; - console.log(math.transpose([[1, 4], [2, 5], [3, 6]])); - state=math.transpose(state); - - var model=scicos_model(); - model.sim=list(new ScilabString(["bounce_ball"]),new ScilabDouble([4])); - model.in=new ScilabDouble(); - model.out=new ScilabDouble([n],[n]); - model.state=new ScilabDouble(...state); - model.rpar=new ScilabDouble(...rpar1,...rpar2,...walls,[g],[C]); - model.ipar=new ScilabDouble(...ipar); - model.nzcross=new ScilabDouble([n*(n-1)/2+4*n]); - model.blocktype=new ScilabString(["c"]); - model.dep_ut=new ScilabBoolean([false,true]); - - var exprs=new ScilabString(); - // var exprs=[strcat(sci2exp(rpar1));strcat(sci2exp(rpar2));strcat(sci2exp(walls));strcat(sci2exp(x));strcat(sci2exp(xd));strcat(sci2exp(y));strcat(sci2exp(yd))] - var gr_i=new ScilabString(["xstringb(orig(1),orig(2),\"BOUNCE\",sz(1),sz(2));"]); - this.x=new standard_define(new ScilabDouble([3,2]),model,exprs,gr_i); - - return new BasicBlock(this.x); }
\ No newline at end of file @@ -273,10 +273,12 @@ function ScilabDouble() { for (i = 0; i < this.height; i++) { for (j = 0; j < this.width; j++) { this["data" + i + j] = new data(); - if(array[i][j] % 1 == 0) + if(array[i][j] % 1 == 0) { this["data" + i + j].realPart = array[i][j].toFixed(1); - else + } + else { this["data" + i + j].realPart = array[i][j]; + } this["data" + i + j].line = i; this["data" + i + j].column = j; } @@ -474,6 +476,7 @@ function BasicBlock() { this.objectsParameters = options.model.opar; this.nbZerosCrossing = options.model.nzcross; this.nmode = options.model.nmode; + this.state = options.model.state; this.oDState = options.model.odstate; this.equations = options.model.equations; this.blockName = "BasicBlock"; |