Данный отчёт сгенерирован 10.02.2023 18:21:31 UTC.
HTML версия (этот сайт) сгенерирован 10.02.2023 18:21:38 UTC.
Коммит: [bfeb65b9] add automatic zip creation 10.02.2023 18:21:31
HTML версия (этот сайт) сгенерирован 10.02.2023 18:21:38 UTC.
Коммит: [bfeb65b9] add automatic zip creation 10.02.2023 18:21:31
Задача: Квадратний корінь
10.02.2023 18:21:31
Описание: Визначте функцію newton(x), яка обчислить квадратний корінь методом Ньютона
з точністю 0.001% від заданого числа x.
Чергове наближення обчислювати за формулою y = (y + x/y)/2.
Не використовувати while, for, sqrt.
10.02.2023 18:21:31
Решений: 41
10.02.2023 18:21:31
Квадратний корінь
10.02.2023 18:21:31
function newton(x){
function found(x, aPrev){
let aCurr = (aPrev + x / aPrev ) / 2
let diff = aPrev - aCurr
return (aPrev - aCurr <= (0.000001*x)) ? aCurr : found(x, aCurr)
}
let a = x / 2
return found(x,a)
}
function newton(x) {
var y = x;
function rec(y) {
if (Math.abs(y * y - x) > 0.001) {
y = (y + x / y) / 2;
return rec(y);
} else {
return y;
}
}
return rec(y);
}
function newton(x) {
return x ** 0.5
}
function newton(x, y = 1) {
const temp = (y + x/y) / 2;
if (Math.abs(y - temp) <= 0.00001) return temp;
return newton(x, temp);
}
function newton(x){
return x**0.5
}
function newton(x){
return x**(1/2)
}
function newton(x) {
function sqrtIter(guess){
if (goodEnaugh(guess)) return guess
else return sqrtIter(improve(guess))
}
function improve(guess){
return average(guess, x/guess)
}
function average(x, y){
return (x+y)/2
}
function goodEnaugh(guess){
if(Math.abs(guess*guess-x)< 0.001)return 1
else return 0
}
return sqrtIter(1.0)
}
function newton(x){
return x**0.5;
}
function newton(x,y=1){// 0.00001
tempY = (y+x/y)/2
if(Math.abs(y-tempY)< 0.00001) return tempY
return newton(x,tempY)
}
function newton(x, depth = 100, y = 1) {
if (depth <= 0) return y;
else return newton(x, depth - 1, y - (Math.pow(y, 2) - x) / (2 * y))
}
function newton(x,y=1){
c = (y+x/y)/2;
if(Math.abs(y-c)< 0.00001){
return c;
}
return newton(x,c);
}
function newton(x){
return x**0.5
}
function newton(x){
var y = x/2
var gef = 0
tod(y)
function tod(y){
y = (y + x/y)/2
if(Math.abs(y-gef) < 0.01){
return gef.toFixed(3);
}
gef = y
tod(y)
}
return gef.toFixed(3)
}
function newton(x, depth = 100, y = 1) {
if (depth <= 0) return y;
else return newton(x, depth - 1, y - (Math.pow(y, 2) - x) / (2 * y))
}
function newton(x){
return x**0.5
}
let y = 1
function newton(x) {
if(y == (y + x/y)/2){
return y
}
else{
y++
return newton(x)
}
}
function newton(x, y = x) {
if (Math.abs(y * y - x) <= x * 0.001) {
return y;
}
return newton(x, (y + x / y) / 2);
}
function newton(x,y=1, n = 0)
{
if(n==1000) return y;
y = (y+x/y)/2;
n++;
return newton(x,y,n);
}
function newton(x){
return x**0.5
}
function newton(x, y=2) {
if (x/y == y) return y;
else return newton (x, (y+x/y)/2);
}
function newton(n,g){
if (!g) {
g = n / 2.0;
}
var d = n / g;
var ng = (d + g) / 2.0;
if (g == ng) {
return g;
}
return newton(n, ng);
}
function newton (x) {
return x ** 0.5
}
function newton(x, y=1, k=4) {
if(k == 0)
return (y+x/y)/2;
return newton(x, (y+x/y)/2, k-1);
}
function newton(x){
return Math.pow(x,1/2)
}
function newton(x) {
function head(guess){
if (precise(guess))
return guess;
return head(fab(guess));
}
function fab(guess){
return 0.5 * (guess + x/guess);
}
function precise(guess){
if(Math.abs(guess**2-x)<0.001)
return 1;
return 0;
}
return head(1.0);
}
let y = 0.5;
function newton(x) {
if((y + x/y)/2 > 0.001 && x/y != y){
y = (y + x/y)/2;
newton(x);
}
return y;
}
function newton(x, n = 6){
if (n) return Math.round((newton(x, n - 1) + x / newton(x, n - 1)) / 2 * 10**5) / 10**5
return 1
}
function newton(x, y=1) {
let a=(y+x/y)/2;
if (Math.abs(y-a) <= 0.00001){
return a;
}
return newton(x, a);
}
function newton(x)
{
let result = x**0.5
return result
}
function newton(x){
return x**0.5
}
function newton(x, y=1, i=4) { // i - точність, 4 = 0.001%, 3 = 0.01%, т.д.
if(i == 0)
return (y+x/y)/2;
return newton(x, (y+x/y)/2, i-1);
}
function newton(x, k = x/2, n = 0){
k = (k + x/k) / 2;
n++;
if(n < 5){
return newton(x, k, n);
}
return k;
}
function newton(x){
if (x == 0) {
return 1;
}
return Math.floor((newton(x-1)+x/newton(x-1))/2);
}
function newton(x){
return x**0.5
}
function newton(x){
function iterSqrt(g){
return goodEnaugh(g) ? g : iterSqrt(improve(g))
}
function improve(g){
return average(g, x/g)
}
function average(x, y) {
return (x+y)/2;
}
function goodEnaugh(g){
if(Math.abs(g**2 - x) < 0.001){
return 1;
}
else{
return 0
}
}
return iterSqrt(1.0)
}
function newton(x){
if(x === 1) return 1;
let n = newton(x - 1);
let result = (n + x / n) / 2;
if(Math.round(result) - result < 1e-15){
return Math.round((n + x / n) / 2);
}
return (n + x / n) / 2;
}
function newton(x, y = x) {
if (Math.abs(y * y - x) <= x * 0.00001) {
return y;
}
return newton(x, (y + x / y) / 2);
}
function newton(x, y){
if (y == undefined) y = 1;
let answ = (y + x/y) / 2;
if (Math.abs(y - answ) <= 0.00001)
return answ;
return newton(x, answ);
}
const newton = x => x ** 0.5;
function newton(x, y = 1) {
y = (y + x/y) / 2;
if(Math.abs(y**2 / x - 1) <= 0.00001)
return y;
return newton(x, y);
}
function newton(x, c = 0, y = 1){
if (c == 6){
return y.toFixed(5)
}
else{
c++;
y = (y+x/y)/2;
newton(x, c, y)
}
}
function found(x, aPrev){
let aCurr = (aPrev + x / aPrev ) / 2
let diff = aPrev - aCurr
return (aPrev - aCurr <= (0.000001*x)) ? aCurr : found(x, aCurr)
}
let a = x / 2
return found(x,a)
}
var y = x;
function rec(y) {
if (Math.abs(y * y - x) > 0.001) {
y = (y + x / y) / 2;
return rec(y);
} else {
return y;
}
}
return rec(y);
}
return x ** 0.5
}
const temp = (y + x/y) / 2;
if (Math.abs(y - temp) <= 0.00001) return temp;
return newton(x, temp);
}
return x**0.5
}
return x**(1/2)
}
function sqrtIter(guess){
if (goodEnaugh(guess)) return guess
else return sqrtIter(improve(guess))
}
function improve(guess){
return average(guess, x/guess)
}
function average(x, y){
return (x+y)/2
}
function goodEnaugh(guess){
if(Math.abs(guess*guess-x)< 0.001)return 1
else return 0
}
return sqrtIter(1.0)
}
return x**0.5;
}
tempY = (y+x/y)/2
if(Math.abs(y-tempY)< 0.00001) return tempY
return newton(x,tempY)
}
if (depth <= 0) return y;
else return newton(x, depth - 1, y - (Math.pow(y, 2) - x) / (2 * y))
}
c = (y+x/y)/2;
if(Math.abs(y-c)< 0.00001){
return c;
}
return newton(x,c);
}
return x**0.5
}
var y = x/2
var gef = 0
tod(y)
function tod(y){
y = (y + x/y)/2
if(Math.abs(y-gef) < 0.01){
return gef.toFixed(3);
}
gef = y
tod(y)
}
return gef.toFixed(3)
}
if (depth <= 0) return y;
else return newton(x, depth - 1, y - (Math.pow(y, 2) - x) / (2 * y))
}
return x**0.5
}
function newton(x) {
if(y == (y + x/y)/2){
return y
}
else{
y++
return newton(x)
}
}
if (Math.abs(y * y - x) <= x * 0.001) {
return y;
}
return newton(x, (y + x / y) / 2);
}
{
if(n==1000) return y;
y = (y+x/y)/2;
n++;
return newton(x,y,n);
}
return x**0.5
}
if (x/y == y) return y;
else return newton (x, (y+x/y)/2);
}
if (!g) {
g = n / 2.0;
}
var d = n / g;
var ng = (d + g) / 2.0;
if (g == ng) {
return g;
}
return newton(n, ng);
}
return x ** 0.5
}
if(k == 0)
return (y+x/y)/2;
return newton(x, (y+x/y)/2, k-1);
}
return Math.pow(x,1/2)
}
function head(guess){
if (precise(guess))
return guess;
return head(fab(guess));
}
function fab(guess){
return 0.5 * (guess + x/guess);
}
function precise(guess){
if(Math.abs(guess**2-x)<0.001)
return 1;
return 0;
}
return head(1.0);
}
function newton(x) {
if((y + x/y)/2 > 0.001 && x/y != y){
y = (y + x/y)/2;
newton(x);
}
return y;
}
if (n) return Math.round((newton(x, n - 1) + x / newton(x, n - 1)) / 2 * 10**5) / 10**5
return 1
}
let a=(y+x/y)/2;
if (Math.abs(y-a) <= 0.00001){
return a;
}
return newton(x, a);
}
{
let result = x**0.5
return result
}
return x**0.5
}
if(i == 0)
return (y+x/y)/2;
return newton(x, (y+x/y)/2, i-1);
}
k = (k + x/k) / 2;
n++;
if(n < 5){
return newton(x, k, n);
}
return k;
}
if (x == 0) {
return 1;
}
return Math.floor((newton(x-1)+x/newton(x-1))/2);
}
return x**0.5
}
function iterSqrt(g){
return goodEnaugh(g) ? g : iterSqrt(improve(g))
}
function improve(g){
return average(g, x/g)
}
function average(x, y) {
return (x+y)/2;
}
function goodEnaugh(g){
if(Math.abs(g**2 - x) < 0.001){
return 1;
}
else{
return 0
}
}
return iterSqrt(1.0)
}
if(x === 1) return 1;
let n = newton(x - 1);
let result = (n + x / n) / 2;
if(Math.round(result) - result < 1e-15){
return Math.round((n + x / n) / 2);
}
return (n + x / n) / 2;
}
if (Math.abs(y * y - x) <= x * 0.00001) {
return y;
}
return newton(x, (y + x / y) / 2);
}
if (y == undefined) y = 1;
let answ = (y + x/y) / 2;
if (Math.abs(y - answ) <= 0.00001)
return answ;
return newton(x, answ);
}
y = (y + x/y) / 2;
if(Math.abs(y**2 / x - 1) <= 0.00001)
return y;
return newton(x, y);
}
if (c == 6){
return y.toFixed(5)
}
else{
c++;
y = (y+x/y)/2;
newton(x, c, y)
}
}