Team:Groningen/Modelling/model/calc.js

function calc{ // gets input var growthFactorNode = document.getElementById("growthFactor");

// reads input var growthFactor = Number(growthFactorNode.value); // begin variable var time = 0; var x = 0; var y = 0; arrValueX = new Array; arrValueY = new Array;

// process var growthFactor = growthFactor + 1; for (var time = 0; time < 30; time++) { var y = growthFactor*x*x; var x = x + 1; arrValueX.push(x); arrValueY.push(y); }

// Set outputs setOutput(growthFactorAnswer, growthFactor ); document.getElementById('modelDataGraph').refresh; }

function setOutput(node,v) { node.innerHTML = formatNumberToHTML(v); node.value = v; }

function formatNumberToHTML(v,p) { if (p===undefined) p = 5; return v.toPrecision(p) .replace(/e\+([0-9]+)$/i,'&middot;10$1') .replace(/e\-([0-9]+)$/i,'&middot;10-$1'); }

// -- Annelies timer functie -

var mijnTimer;

function tijd{ // gets input var timeMiliSecNode = document.getElementById("timeMiliSec"); // reads input var timeMiliSec2 = Number(timeMiliSecNode.value);

//alert("functie tijd: "+timeMiliSec2);

if (mijnTimer) clearInterval(mijnTimer); mijnTimer = setInterval( "doSomething",timeMiliSec2); }

function doSomething{ //alert("functie doe iets BOVEN DE IF LUS: "+doSomething.time);

if (doSomething.time === undefined) {

doSomething.time = 0; //alert("functie doe ietsFDBADFNA: "+doSomething.time); }

// Set outputs setOutput(tijdAnswer, doSomething.time); doSomething.time += 1; transport; }

// transport model, geeft waarden mee in een object/array --

function transport{

// variablen var data = {time: [0], AsIn: [0], ArsB: [5], AsEx: [5], GlpF: [5], GlpFAs: [0], ArsBAs: [0]};

// constanten var totalTime = 300; var stepSize = 0.1; var K5on = 1; var K5off = 1e-6; var K6 = 1e-3; var Vc = 1.1 - 0.0073; var Vs = 0.0073; var K7on = 1; var K7off = 1e-6; var K8 = 1e-3;

var N = totalTime / stepSize ;

for (var i=1;i<=N;i++){ data.GlpFAs[i] = data.GlpFAs[i-1] + stepSize * (K5on * data.AsEx[i-1] * data.GlpF[i-1] - (K5off + K6) * data.GlpFAs[i-1]); data.AsEx[i] = data.AsEx[i-1] + stepSize * (-K5on * data.AsEx[i-1] * data.GlpF[i-1] + K5off * data.GlpFAs[i-1] + (Vc/Vs) * K8 * data.ArsBAs[i-1]); data.GlpF[i] = data.GlpF[i-1] + stepSize * (-(K5on * data.AsEx[i-1] * data.GlpF[i-1] - (K5off + K6) * data.GlpFAs[i-1])); data.ArsBAs[i] = data.ArsBAs[i-1] + stepSize * (K7on * data.AsIn[i-1] * data.ArsB[i-1] - (K7off+K8) * data.ArsBAs[i-1]); data.AsIn[i] = data.AsIn[i-1] + stepSize * (-K7on * data.AsIn[i-1] * data.ArsB[i-1] - (K7off + K8) * data.ArsBAs[i-1] - K8 * data.ArsBAs[i-1] + (Vs/Vc) * K6 * data.GlpFAs[i-1]); data.ArsB[i] = data.ArsB[i-1] + stepSize * (-(K7on * data.AsIn[i-1] * data.ArsB[i-1] - (K7off + K8) * data.ArsBAs[i-1])); data.time[i] = data.time[i-1] + stepSize; }

setOutput(ModelAnswer, data.AsEx[4]); var modelDataNode = document.getElementById("modelData"); modelDataNode.data = data;

document.getElementById("modelDataGraph").refresh; }

// --- het gehele model ---

function modelTotal{

alert("hallo");

// Definieren van begincondities dit zijn dus constanten die later niet gebruikt worden //Begincondities (op tijdstip nul) die in het 0-de element van een array moeten worden gezet. var data = { AsexT: [5], ArsBas: [0], GlpFas: [0], GlpFT: [5], ArsBT: [5], AsinT: [0], ars1T: [5], ars2T: [5], pro:   [5], ArsRT: [5], GV:    [0], Time:  [0], ArsB: [0], Asin: [0], ArsR: [0], ars:  [0], GlpF: [0], ArsRas:[0], ars1:  [0], ars2:  [0], arsT:  [0], ArsRars:[0], Asex:  [0]};

// Begincondities die constantes blijven var Vc = 10; var TotalTime = 10; // 10 seconds var Timestep = 0.01; // 1/100th of a second //var N = TotalTime/Timestep;

var N = 5;

var K5 = 10; var Vs = 10; var K7 = 10; var k8 = 10; var v5 = 10; var tauG = 10; var tauB = 10; var tauR = 10; var Beta5 = 10; var Beta4 = 10; var Beta3 = 10; var Beta1 = 10; var K3d = 0.33; // micromolair; var K1d = K3d/10; //Er komen nog een hoop nieuwe variabelen aan stop ze tenzij anders aangegeven allemaal in een Array //We stoppen nu het gehele programma in een loop (Ik doe een forloop, je moet zelf maar kijken wat het handigst is.) var TOL = 10^-6; var getal = 500;

function nonnegative(v) { /*return v>=0?v:0;*/ return v; }

for(var i = 0 ; i < N ; i++) { //We passen nu eerst Newton's methode toe // Eerst maken we een Array X met de Afschatting van de variabelen

var x =new Array(7); x[0] = data.ArsBT[i]/2; //(ArsB) x[1] = data.Asex[i]/10; // Asin x[2] = data.ArsRT[i]/3; // ArsR x[3] = data.ArsRT[i]/3; // ars x[4] = data.GlpF[i]/2; // GlpF x[5] = data.ArsRT[i]/3; // ArsRas x[6] = data.Asex[i]/2; // Asex

//Nu maken we weer een forloop aan var Yvalue = TOL+1; for ( var j = 1; j <= N && Yvalue>TOL; j++) {

var F = new Array(6); F[0] = ((data.ArsBT[i] * K7) / (x[1] + K7)) - x[0]; F[1] = ((data.AsinT[i] / (1 + (x[2] / K1d) + (x[0]) / K7))) - x[1]; F[2] = ((data.ArsRT[i]) / (1 + (x[1] / K1d) + (2 * x[2] * x[3] / K3d))) - x[2]; F[3] = ((K3d) / (Math.pow(x[2],2) + K3d)) - x[3] ; F[4] = ((data.GlpFT[i] * K5) / (x[6] + K5)) - x[4]; F[5] = ((data.ArsRT[i] * x[1] / K1d) / (1 + (x[1] / K1d) + (2 * x[2] * x[3] / K3d))) - x[5]; F[6] = ((data.AsexT[i] * K5) / (K5 + x[4])) - x[6];

//Hierna maken we een Matrix 7x7 matrix aan var matrix = new Array(7); matrix[0] = new Array(7); matrix[1] = new Array(7); matrix[2] = new Array(7); matrix[3] = new Array(7); matrix[4] = new Array(7); matrix[5] = new Array(7); matrix[6] = new Array(7);

matrix[0][0] = -1; matrix[0][1] = 0; matrix[0][2] = 0; matrix[0][3] = 0; matrix[0][4] = 0; matrix[0][5] = 0; matrix[0][6] = 0; matrix[1][0] = 0; matrix[1][1] = -1; matrix[1][2] = 0; matrix[1][3] = 0; matrix[1][4] = 0; matrix[1][5] = 0; matrix[1][6] = 0; matrix[2][0] = 0; matrix[2][1] = 0; matrix[2][2] = (-2 * Math.pow(((data.ArsRT[i]) / (1 + (x[1] / K1d) + (2 * x[2] * x[3] / K3d))),2) - 1); matrix[2][3] = 0; matrix[2][4] = 0; matrix[2][5] = 0; matrix[2][6] = 0; matrix[3][0] = 0; matrix[3][1] = 0; matrix[3][2] = 0; matrix[3][3] = -1; matrix[3][4] = 0; matrix[3][5] = 0; matrix[3][6] = 0; matrix[4][0] = 0; matrix[4][1] = 0; matrix[4][2] = 0; matrix[4][3] = 0; matrix[4][4] = -1; matrix[4][5] = 0; matrix[4][6] = 0; matrix[5][0] = 0; matrix[5][1] = 0; matrix[5][2] = 0; matrix[5][3] = 0; matrix[5][4] = 0; matrix[5][5] = -1; matrix[5][6] = 0; matrix[6][0] = 0; matrix[6][1] = 0; matrix[6][2] = 0; matrix[6][3] = 0; matrix[6][4] = 0; matrix[6][5] = 0; matrix[6][6] = -1;

//Nu maken we een Array Y aan var y =new Array(7); y[0] = F[0]/ matrix[0][0]; y[1] = F[1]/ matrix[1][1]; y[2] = F[2]/ matrix[2][2]; y[3] = F[3]/ matrix[3][3]; y[4] = F[4]/ matrix[4][4]; y[5] = F[5]/ matrix[5][5]; y[6] = F[6]/ matrix[6][6]; // Math.abs om de Y waarden zetten (bijv. Math.abs(Y(0))) Yvalue = Math.abs(y[0]) + Math.abs(y[1]) + Math.abs(y[2]) + Math.abs(y[3]) + Math.abs(y[4]) + Math.abs(y[5]) + Math.abs(y[6]);

for (var k = 0 ; k <= 6 ; k++) { x[k] = x[k] + y[k]; }	 }

data.ArsB[i]  = nonnegative(x[0]); data.Asin[i]  = nonnegative(x[1]); data.ArsR[i]  = nonnegative(x[2]); data.ars[i]   = nonnegative(x[3]); data.GlpF[i]  = nonnegative(x[4]); data.ArsRas[i] = nonnegative(x[5]); data.Asex[i]  = nonnegative(x[6]);

//Nu gaan we verdere variabelen opstellen ook deze moeten weer in Array's komen te staan var k6 = (v5 * Vc) / (data.GlpFT[i] * Vs); data.ars1[i] = nonnegative((data.ars1T[i] * K3d) /(K3d + Math.pow(data.ArsR[i],2))); data.ars2[i] = nonnegative((data.ars2T[i] * K3d) /(K3d + Math.pow(data.ArsR[i],2)));

data.ArsBas[i] = nonnegative(data.ArsBT[i] - data.ArsB[i]); data.GlpFas[i] = nonnegative(data.GlpFT[i] - data.GlpF[i]); data.arsT[i] = nonnegative(data.ars1T[i] + data.ars2T[i]); data.ArsRars[i] = nonnegative(data.arsT[i] - data.ars[i]); data.Asex[i] = nonnegative(data.AsexT[i] - data.GlpFas[i]);

// ln is niet gedifineerd, alleen ln[2] wordt gebruikt is dit een array of een variable // Math.log(x) Math.LN2

//We gaan nu met Eulers methode de volgende slag voorbereiden data.AsexT[i+1] = nonnegative(data.AsexT[i] + Timestep*((Vc/Vs)*k8*data.ArsBas[i]-k6*data.GlpFas[i])); data.GlpFT[i+1] = data.GlpFT[i]; // mag deze wel negatief worden?? data.ArsBT[i+1] = nonnegative(data.ArsBT[i] + Timestep*(Beta4*data.ars1[i] - Math.LN2/(tauB * data.ArsB[i]))); data.AsinT[i+1] = nonnegative(data.AsinT[i] + Timestep*((Vs/Vc)*k6*data.GlpFas[i]-k8*data.ArsBas[i])); data.ars1T[i+1] = nonnegative(data.ars1T[i]); data.ars2T[i+1] = nonnegative(data.ars2T[i]); data.pro[i+1] = nonnegative(data.pro[i]); alert("data.ArsRT[i] "+ data.ArsRT[i]); data.ArsRT[i+1] = nonnegative(data.ArsRT[i] + Timestep*(Beta1*data.ars1[i] + Beta3*data.pro[i]-(Math.LN2/tauR)*data.ArsR[i])); data.GV[i+1] = nonnegative(data.GV[i] + Timestep*(Beta5*data.ars2[i] - Math.LN2*tauG*data.GV[i])); data.Time[i+1] = nonnegative(data.Time[i] + Timestep); }

var TotalmodelNode = document.getElementById("Totalmodel"); TotalmodelNode.data = data; document.getElementById("TotalmodelGraph").refresh;

} // end function modeltotal