我需要你的帮助将这个新割线方法编码成 Javascript。
割线法使用两个起始参数,而这种新方法只需要一个起始参数。
先感谢您。
感谢您的回答[编辑:评论],这是我尝试过的,但它不起作用:
<script>
var x
var pi = 3.141592653589793, e = 2.7182818284590452;
function meth_sec() {
with (Math) {
f = "sin(x)-x/2"; a = 1; s = 1;
f = prompt("your function f(x) = ", f)
while (s >= 0) {
a = eval(prompt("type the approximation. = ", a))
x = a;
}
}
} function iter() {
with (Math) {
y = eval(f)
x = a + (abs(y)/2) - abs(y)*((y(a+abs(y/2)))/((y(a+abs(y/2)))-y)
return x
}
}
function sgn(y) { return (y > 0) - (y < 0) }
</script>