首页 > 其他 > 详细

解方程 (允许误差)

时间:2014-07-01 08:14:27      阅读:287      评论:0      收藏:0      [点我收藏+]
解方程 (允许误差)


1. 确定范围
2. 确定误差
3. 确定增量
4. 在区间内执行方程,满足误差存入解集
5. 返回解集


var solveFun = function(
f /*function*/,
c /*closest to 0*/,
from /*from what number*/,
to /*to what number*/,
ic /*increasement*/){


var arr = new Array();
for(var i =from ; i <= to ; i+=ic){
var r = f(i);
if(Math.abs(r) <= c) {arr.push({x:i,y:r});}
}


if(arr.length == 0) {return undefined;}


return arr;
}


var ret = solveFun(function (n){return n*n*n -3*n + 1},0.001,-10,20,0.001);


if(ret == undefined){console.log("no answer.");}


else {
console.log(ret.length + "answer found ");
for(var i = 0 ;i < ret.length; i++)
console.log("x = " + ret[i].x + ", y= " + ret[i].y);


}


解方程 (允许误差),布布扣,bubuko.com

解方程 (允许误差)

原文:http://blog.csdn.net/lan_liang/article/details/36014263

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!