Created
December 2, 2012 10:43
-
-
Save SeqviriouM/4188130 to your computer and use it in GitHub Desktop.
Mnogomerpoisk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var f = function(x1,x2) | |
{ | |
return (x1-5)*(x1-5)+(x2-4)*(x2-4) | |
} | |
var func = function(a,b,c,d,s) | |
{ | |
return (a-s*b-5)*(a-s*b-5)+(c-s*d-4)*(c-s*d-4); | |
} | |
var func1 = function(a,b,c,d,s) | |
{ | |
return 2*b*(a-s*b-5)+2*d*(c-s*d-4); | |
} | |
var df = function(x1,x2) | |
{ | |
return [[2*x1-10],[2*x2-8]]; | |
} | |
var fi = function(a,b,c,d) | |
{ | |
var func = (a-s*b-5)*(a-s*b-5)+(c-s*d-4)*(c-s*d-4); | |
var begin,end,mid,j | |
begin = 0; | |
end = 100; | |
mid = (begin+end)/2; | |
j=0; | |
while (Math.abs(func1(a,b,c,d,mid)) > 0.01) | |
{ | |
if (func1(a,b,c,d,mid) > 0) | |
{ | |
begin = mid | |
} | |
else | |
{ | |
end = mid | |
} | |
mid = (begin+end)/2; | |
j++; | |
} | |
return mid; | |
} | |
var d2f = [[2,0],[0,2]]; | |
var d2fobr = [[0.5,0],[0,0.5]] | |
var x0 = [[0],[0]] | |
var x1 = [[],[]] | |
j = 0; | |
var s; | |
while (Math.sqrt(df(x0[0][0],x0[1][0])[0][0]*df(x0[0][0],x0[1][0])[0][0]+df(x0[0][0],x0[1][0])[1][0]*df(x0[0][0],x0[1][0])[1][0]) > 0.01) | |
{ | |
s = fi(x0[0][0],d2fobr[0][0]*df(x0[0][0],x0[1][0])[0][0],x0[1][0],d2fobr[1][1]*df(x0[0][0],x0[1][0])[1][0]) | |
x1[0][0] = (x0[0][0]-s*d2fobr[0][0]*df(x0[0][0],x0[1][0])[0][0]).toFixed(3); | |
x1[1][0] = (x0[1][0]-s*d2fobr[1][1]*df(x0[0][0],x0[1][0])[1][0]).toFixed(3); | |
x0[0] = x1[0].slice(0); | |
x0[1] = x1[1].slice(0); | |
j++; | |
} | |
alert(x0 + " за " + j + " итерацию") | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment