exports.create = function(req, res) { // don't include the date, if a user specified it delete req.body.date; //console.log("reqqqqqqqqqqqqqq USERRRRRERRRRRRR"); //console.log(req.user); //console.log("reqBBBBBBBBBBBBBBBBBBBBBBBBBBOOOOOOOOOOOOOOOOOOOOOODDDDDDDDDDDDDYYYYYYYYYYY") //console.log(req.body) //console.log("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD") var array = req.body.content.split(','); //console.log(array); var i = 0; var text = ""; for (i = 0; i < 2; i++) { text += array[i] + ","; //console.log(math.sin(parseFloat(array[i]))); if (i === 1) { //console.log("CCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOSSSSSSSSSSSSSSSS"); //console.log(math.sin(parseFloat(array[i]))); text += math.cos(parseFloat(array[i])).toFixed(4); break; } text += math.sin(parseFloat(array[i])).toFixed(4) + ","; } req.body.content = text; //console.log(text); //console.log(req.body); //console.log(req.user._id) var comment = new Comment(_.merge({ author: "558194cfe4380850581ba76b" }, req.body)); comment.save(function(err, comment) { if (err) { return handleError(res, err); } return res.json(201, comment); }); 0 };
//統計運算 console.log(math.sum(2,1,4,3)); //總和 console.log(math.sum([[2,5],[4,3],[1,7]])); //矩陣總和 console.log(math.max(2,1,4,3)); //取最大值 console.log(math.max([[2,5],[4,3],[1,7]])); //矩陣取最大值 console.log(math.min(2,1,4,3)); //取最小值 console.log(math.min([[2,5],[4,3],[1,7]])); //矩陣取最小值 console.log(math.mean(2,1,4,3)); //取平均值 console.log(math.mean([[2,5],[6,3],[1,7]])); //矩陣取平均值 console.log(math.median(6,2,7)); //取中間數 console.log(math.median([3,-1,5,7])); //偶數時取中間哪個數的平均 console.log('---------------------------------------'); //三角函數 console.log(math.sin(0.5)); //sin(x) console.log(math.cos(0.5)); //cos(x) console.log(math.tan(0.5)); //tan(x) console.log('---------------------------------------'); //tools console.log(math.to(math.unit('2 inch'),'cm').toString()); //將英吋轉為公分 console.log(math.clone('Hello world!')); //複製 var isPositive = function(x){return x>0;} //建立一個只回傳正數的函式 console.log(math.filter([6,-2,-1,4,3],isPositive)); //過濾掉負數 math.forEach([1,2,3],function(value){console.log(value);}); //依序執行 console.log(math.sort([5,1,10])); //數字排序 console.log(math.sort(['C','A','D','B'])); //字母排序 var sortByLength = function(a,b){return a.length-b.length;}; //建立長度比較函式 console.log(math.sort(['English','Alex','GG'],sortByLength)); //使用長度排序 console.log(math.typeof(3.5)); //判斷型態 console.log(math.typeof('hello')); //判斷型態
, WIN = 1024 , frameRate = 44100 , times, signal, re, im, amplitudes var writeValuesToFile = function(filename, x, y) { var dataStr = '' y.forEach(function(val, i) { dataStr += '' + x[i] + ' ' + val + '\n' }) fs.writeFileSync(filename, dataStr) } // Generate a signal cos(2PI 500 t) + cos(2PI 1500 t) times = math.emultiply(math.range(0, WIN - 1).toMatrix(), 1 / frameRate) signal = math.add( math.multiply(math.cos(math.emultiply(times, 2 * math.PI * 500)), 0.6), math.multiply(math.cos(math.emultiply(times, 2 * math.PI * 1500)), 0.35) ) re = signal.toArray() im = math.squeeze(math.zeros([1, WIN])).toArray() // Compute the frequency spectrum with a FFT fft(1, re, im) amplitudes = math.epow(math.add(math.epow(re, 2), math.epow(im, 2)), 0.5) amplitudes = math.emultiply(amplitudes, 2/WIN) // Recompute the original signal by performing the inverse transform fft(-1, re, im) // Only positive frequencies writeValuesToFile('signal.dat', times.toArray(), signal.toArray())
var modelF = function(x) { return 6*x - math.cos(x)/(1+x)*(x*math.pow(x, 2) + 2) - (2-x)*(math.pow(x, 3) + 2*x - 3) };
var p = function(x) { return -math.cos(x) / (1 + x); };