読者です 読者をやめる 読者になる 読者になる

INFINITY -数学とかプログラミングとか-

統計とプログラムを使って役に立たせたい

TeX用コマンド入力を支援するための辞書をご利用ください。
sanctuary's blogは,適当なことが書いてあります。

メモ(勾配降下法(最急降下法))

func2=function(t){
return(t^4)
}

dffunc2=function(t){
return(4*t^3)
}


grad2=function(x,rho,its){
	cnt=1
	for(i in 1:its){
		xbefore=x
		x=x-rho*dffunc2(x)

		if(0==cnt%%1000000){
			printf("cnt:%d;x=%f,abs(x-xbefore)=%.13f\n",cnt,x,abs(x-xbefore))
		}

		if(abs(x-xbefore)<=1.0e-10){
			printf("cnt:%d;x=%f,abs(x-xbefore)=%.13f\n",cnt,x,abs(x-xbefore))			
			break
		}
		cnt=cnt+1
	}
}


#grad2(-2,2,100)
#発散

grad2(-1,0.01,100000000)
> grad2(-1,0.01,100000000)
cnt:1000000;x=-0.003535,abs(x-xbefore)=0.0000000017677
cnt:2000000;x=-0.002500,abs(x-xbefore)=0.0000000006250
cnt:3000000;x=-0.002041,abs(x-xbefore)=0.0000000003402
cnt:4000000;x=-0.001768,abs(x-xbefore)=0.0000000002210
cnt:5000000;x=-0.001581,abs(x-xbefore)=0.0000000001581
cnt:6000000;x=-0.001443,abs(x-xbefore)=0.0000000001203
cnt:6786023;x=-0.001357,abs(x-xbefore)=0.0000000001000
> grad21=function(x,rho,its){
+ cnt=1
+ for(i in 1:its){
+ xbefore=x
+ x=x-rho*dffunc2(x)
+ 
+ if(cnt==1||0==cnt%%10000){
+ printf("cnt:%d;x=%f,abs(x-xbefore)=%.13f\n",cnt,x,abs(x-xbefore))
+ }
+ 
+ if(abs(x-xbefore)<=1.0e-10){
+ printf("cnt:%d;x=%f,abs(x-xbefore)=%.13f\n",cnt,x,abs(x-xbefore))
+ break
+ }
+ cnt=cnt+1
+ }
+ }
> 
> grad21(-1,0.1,100000000)
cnt:1;x=-0.600000,abs(x-xbefore)=0.4000000000000
cnt:10000;x=-0.011176,abs(x-xbefore)=0.0000005583841
cnt:20000;x=-0.007904,abs(x-xbefore)=0.0000001975227
cnt:30000;x=-0.006454,abs(x-xbefore)=0.0000001075378
cnt:40000;x=-0.005589,abs(x-xbefore)=0.0000000698546
cnt:50000;x=-0.005000,abs(x-xbefore)=0.0000000499869
cnt:60000;x=-0.004564,abs(x-xbefore)=0.0000000380278
cnt:70000;x=-0.004225,abs(x-xbefore)=0.0000000301783
cnt:80000;x=-0.003953,abs(x-xbefore)=0.0000000247011
cnt:90000;x=-0.003727,abs(x-xbefore)=0.0000000207012
cnt:100000;x=-0.003535,abs(x-xbefore)=0.0000000176752
cnt:110000;x=-0.003371,abs(x-xbefore)=0.0000000153208
cnt:120000;x=-0.003227,abs(x-xbefore)=0.0000000134463
cnt:130000;x=-0.003101,abs(x-xbefore)=0.0000000119251
cnt:140000;x=-0.002988,abs(x-xbefore)=0.0000000106706
cnt:150000;x=-0.002887,abs(x-xbefore)=0.0000000096216
cnt:160000;x=-0.002795,abs(x-xbefore)=0.0000000087339
cnt:170000;x=-0.002712,abs(x-xbefore)=0.0000000079747
cnt:180000;x=-0.002635,abs(x-xbefore)=0.0000000073195
cnt:190000;x=-0.002565,abs(x-xbefore)=0.0000000067493
cnt:200000;x=-0.002500,abs(x-xbefore)=0.0000000062495
cnt:210000;x=-0.002440,abs(x-xbefore)=0.0000000058085
cnt:220000;x=-0.002384,abs(x-xbefore)=0.0000000054170
cnt:230000;x=-0.002331,abs(x-xbefore)=0.0000000050676
cnt:240000;x=-0.002282,abs(x-xbefore)=0.0000000047542
cnt:250000;x=-0.002236,abs(x-xbefore)=0.0000000044719
cnt:260000;x=-0.002193,abs(x-xbefore)=0.0000000042164
cnt:270000;x=-0.002152,abs(x-xbefore)=0.0000000039843
cnt:280000;x=-0.002113,abs(x-xbefore)=0.0000000037728
cnt:290000;x=-0.002076,abs(x-xbefore)=0.0000000035794
cnt:300000;x=-0.002041,abs(x-xbefore)=0.0000000034019
cnt:310000;x=-0.002008,abs(x-xbefore)=0.0000000032386
cnt:320000;x=-0.001976,abs(x-xbefore)=0.0000000030880
cnt:330000;x=-0.001946,abs(x-xbefore)=0.0000000029487
cnt:340000;x=-0.001917,abs(x-xbefore)=0.0000000028196
cnt:350000;x=-0.001890,abs(x-xbefore)=0.0000000026996
cnt:360000;x=-0.001863,abs(x-xbefore)=0.0000000025879
cnt:370000;x=-0.001838,abs(x-xbefore)=0.0000000024837
cnt:380000;x=-0.001814,abs(x-xbefore)=0.0000000023863
cnt:390000;x=-0.001790,abs(x-xbefore)=0.0000000022951
cnt:400000;x=-0.001768,abs(x-xbefore)=0.0000000022096
cnt:410000;x=-0.001746,abs(x-xbefore)=0.0000000021293
cnt:420000;x=-0.001725,abs(x-xbefore)=0.0000000020537
cnt:430000;x=-0.001705,abs(x-xbefore)=0.0000000019825
cnt:440000;x=-0.001685,abs(x-xbefore)=0.0000000019153
cnt:450000;x=-0.001667,abs(x-xbefore)=0.0000000018518
cnt:460000;x=-0.001648,abs(x-xbefore)=0.0000000017917
cnt:470000;x=-0.001631,abs(x-xbefore)=0.0000000017349
cnt:480000;x=-0.001614,abs(x-xbefore)=0.0000000016809
cnt:490000;x=-0.001597,abs(x-xbefore)=0.0000000016297
cnt:500000;x=-0.001581,abs(x-xbefore)=0.0000000015811
cnt:510000;x=-0.001566,abs(x-xbefore)=0.0000000015348
cnt:520000;x=-0.001550,abs(x-xbefore)=0.0000000014908
cnt:530000;x=-0.001536,abs(x-xbefore)=0.0000000014488
cnt:540000;x=-0.001521,abs(x-xbefore)=0.0000000014087
cnt:550000;x=-0.001508,abs(x-xbefore)=0.0000000013705
cnt:560000;x=-0.001494,abs(x-xbefore)=0.0000000013339
cnt:570000;x=-0.001481,abs(x-xbefore)=0.0000000012990
cnt:580000;x=-0.001468,abs(x-xbefore)=0.0000000012655
cnt:590000;x=-0.001456,abs(x-xbefore)=0.0000000012335
cnt:600000;x=-0.001443,abs(x-xbefore)=0.0000000012028
cnt:610000;x=-0.001431,abs(x-xbefore)=0.0000000011733
cnt:620000;x=-0.001420,abs(x-xbefore)=0.0000000011451
cnt:630000;x=-0.001409,abs(x-xbefore)=0.0000000011179
cnt:640000;x=-0.001398,abs(x-xbefore)=0.0000000010918
cnt:650000;x=-0.001387,abs(x-xbefore)=0.0000000010667
cnt:660000;x=-0.001376,abs(x-xbefore)=0.0000000010426
cnt:670000;x=-0.001366,abs(x-xbefore)=0.0000000010193
cnt:680000;x=-0.001356,abs(x-xbefore)=0.0000000009969
cnt:690000;x=-0.001346,abs(x-xbefore)=0.0000000009753
cnt:700000;x=-0.001336,abs(x-xbefore)=0.0000000009545
cnt:710000;x=-0.001327,abs(x-xbefore)=0.0000000009344
cnt:720000;x=-0.001318,abs(x-xbefore)=0.0000000009150
cnt:730000;x=-0.001309,abs(x-xbefore)=0.0000000008963
cnt:740000;x=-0.001300,abs(x-xbefore)=0.0000000008781
cnt:750000;x=-0.001291,abs(x-xbefore)=0.0000000008606
cnt:760000;x=-0.001282,abs(x-xbefore)=0.0000000008437
cnt:770000;x=-0.001274,abs(x-xbefore)=0.0000000008273
cnt:780000;x=-0.001266,abs(x-xbefore)=0.0000000008115
cnt:790000;x=-0.001258,abs(x-xbefore)=0.0000000007961
cnt:800000;x=-0.001250,abs(x-xbefore)=0.0000000007812
cnt:810000;x=-0.001242,abs(x-xbefore)=0.0000000007668
cnt:820000;x=-0.001235,abs(x-xbefore)=0.0000000007528
cnt:830000;x=-0.001227,abs(x-xbefore)=0.0000000007393
cnt:840000;x=-0.001220,abs(x-xbefore)=0.0000000007261
cnt:850000;x=-0.001213,abs(x-xbefore)=0.0000000007133
cnt:860000;x=-0.001206,abs(x-xbefore)=0.0000000007009
cnt:870000;x=-0.001199,abs(x-xbefore)=0.0000000006889
cnt:880000;x=-0.001192,abs(x-xbefore)=0.0000000006772
cnt:890000;x=-0.001185,abs(x-xbefore)=0.0000000006658
cnt:900000;x=-0.001179,abs(x-xbefore)=0.0000000006547
cnt:910000;x=-0.001172,abs(x-xbefore)=0.0000000006440
cnt:920000;x=-0.001166,abs(x-xbefore)=0.0000000006335
cnt:930000;x=-0.001159,abs(x-xbefore)=0.0000000006233
cnt:940000;x=-0.001153,abs(x-xbefore)=0.0000000006134
cnt:950000;x=-0.001147,abs(x-xbefore)=0.0000000006037
cnt:960000;x=-0.001141,abs(x-xbefore)=0.0000000005943
cnt:970000;x=-0.001135,abs(x-xbefore)=0.0000000005851
cnt:980000;x=-0.001129,abs(x-xbefore)=0.0000000005762
cnt:990000;x=-0.001124,abs(x-xbefore)=0.0000000005675
cnt:1000000;x=-0.001118,abs(x-xbefore)=0.0000000005590
cnt:1010000;x=-0.001112,abs(x-xbefore)=0.0000000005507
cnt:1020000;x=-0.001107,abs(x-xbefore)=0.0000000005426
cnt:1030000;x=-0.001102,abs(x-xbefore)=0.0000000005348
cnt:1040000;x=-0.001096,abs(x-xbefore)=0.0000000005271
cnt:1050000;x=-0.001091,abs(x-xbefore)=0.0000000005196
cnt:1060000;x=-0.001086,abs(x-xbefore)=0.0000000005122
cnt:1070000;x=-0.001081,abs(x-xbefore)=0.0000000005051
cnt:1080000;x=-0.001076,abs(x-xbefore)=0.0000000004981
cnt:1090000;x=-0.001071,abs(x-xbefore)=0.0000000004912
cnt:1100000;x=-0.001066,abs(x-xbefore)=0.0000000004845
cnt:1110000;x=-0.001061,abs(x-xbefore)=0.0000000004780
cnt:1120000;x=-0.001056,abs(x-xbefore)=0.0000000004716
cnt:1130000;x=-0.001052,abs(x-xbefore)=0.0000000004654
cnt:1140000;x=-0.001047,abs(x-xbefore)=0.0000000004593
cnt:1150000;x=-0.001043,abs(x-xbefore)=0.0000000004533
cnt:1160000;x=-0.001038,abs(x-xbefore)=0.0000000004474
cnt:1170000;x=-0.001034,abs(x-xbefore)=0.0000000004417
cnt:1180000;x=-0.001029,abs(x-xbefore)=0.0000000004361
cnt:1190000;x=-0.001025,abs(x-xbefore)=0.0000000004306
cnt:1200000;x=-0.001021,abs(x-xbefore)=0.0000000004253
cnt:1210000;x=-0.001016,abs(x-xbefore)=0.0000000004200
cnt:1220000;x=-0.001012,abs(x-xbefore)=0.0000000004148
cnt:1230000;x=-0.001008,abs(x-xbefore)=0.0000000004098
cnt:1240000;x=-0.001004,abs(x-xbefore)=0.0000000004048
cnt:1250000;x=-0.001000,abs(x-xbefore)=0.0000000004000
cnt:1260000;x=-0.000996,abs(x-xbefore)=0.0000000003952
cnt:1270000;x=-0.000992,abs(x-xbefore)=0.0000000003906
cnt:1280000;x=-0.000988,abs(x-xbefore)=0.0000000003860
cnt:1290000;x=-0.000984,abs(x-xbefore)=0.0000000003815
cnt:1300000;x=-0.000981,abs(x-xbefore)=0.0000000003771
cnt:1310000;x=-0.000977,abs(x-xbefore)=0.0000000003728
cnt:1320000;x=-0.000973,abs(x-xbefore)=0.0000000003686
cnt:1330000;x=-0.000969,abs(x-xbefore)=0.0000000003645
cnt:1340000;x=-0.000966,abs(x-xbefore)=0.0000000003604
cnt:1350000;x=-0.000962,abs(x-xbefore)=0.0000000003564
cnt:1360000;x=-0.000959,abs(x-xbefore)=0.0000000003525
cnt:1370000;x=-0.000955,abs(x-xbefore)=0.0000000003486
cnt:1380000;x=-0.000952,abs(x-xbefore)=0.0000000003448
cnt:1390000;x=-0.000948,abs(x-xbefore)=0.0000000003411
cnt:1400000;x=-0.000945,abs(x-xbefore)=0.0000000003375
cnt:1410000;x=-0.000942,abs(x-xbefore)=0.0000000003339
cnt:1420000;x=-0.000938,abs(x-xbefore)=0.0000000003304
cnt:1430000;x=-0.000935,abs(x-xbefore)=0.0000000003269
cnt:1440000;x=-0.000932,abs(x-xbefore)=0.0000000003235
cnt:1450000;x=-0.000928,abs(x-xbefore)=0.0000000003202
cnt:1460000;x=-0.000925,abs(x-xbefore)=0.0000000003169
cnt:1470000;x=-0.000922,abs(x-xbefore)=0.0000000003136
cnt:1480000;x=-0.000919,abs(x-xbefore)=0.0000000003105
cnt:1490000;x=-0.000916,abs(x-xbefore)=0.0000000003074
cnt:1500000;x=-0.000913,abs(x-xbefore)=0.0000000003043
cnt:1510000;x=-0.000910,abs(x-xbefore)=0.0000000003013
cnt:1520000;x=-0.000907,abs(x-xbefore)=0.0000000002983
cnt:1530000;x=-0.000904,abs(x-xbefore)=0.0000000002954
cnt:1540000;x=-0.000901,abs(x-xbefore)=0.0000000002925
cnt:1550000;x=-0.000898,abs(x-xbefore)=0.0000000002897
cnt:1560000;x=-0.000895,abs(x-xbefore)=0.0000000002869
cnt:1570000;x=-0.000892,abs(x-xbefore)=0.0000000002842
cnt:1580000;x=-0.000889,abs(x-xbefore)=0.0000000002815
cnt:1590000;x=-0.000887,abs(x-xbefore)=0.0000000002788
cnt:1600000;x=-0.000884,abs(x-xbefore)=0.0000000002762
cnt:1610000;x=-0.000881,abs(x-xbefore)=0.0000000002736
cnt:1620000;x=-0.000878,abs(x-xbefore)=0.0000000002711
cnt:1630000;x=-0.000876,abs(x-xbefore)=0.0000000002686
cnt:1640000;x=-0.000873,abs(x-xbefore)=0.0000000002662
cnt:1650000;x=-0.000870,abs(x-xbefore)=0.0000000002638
cnt:1660000;x=-0.000868,abs(x-xbefore)=0.0000000002614
cnt:1670000;x=-0.000865,abs(x-xbefore)=0.0000000002590
cnt:1680000;x=-0.000863,abs(x-xbefore)=0.0000000002567
cnt:1690000;x=-0.000860,abs(x-xbefore)=0.0000000002544
cnt:1700000;x=-0.000857,abs(x-xbefore)=0.0000000002522
cnt:1710000;x=-0.000855,abs(x-xbefore)=0.0000000002500
cnt:1720000;x=-0.000852,abs(x-xbefore)=0.0000000002478
cnt:1730000;x=-0.000850,abs(x-xbefore)=0.0000000002457
cnt:1740000;x=-0.000848,abs(x-xbefore)=0.0000000002436
cnt:1750000;x=-0.000845,abs(x-xbefore)=0.0000000002415
cnt:1760000;x=-0.000843,abs(x-xbefore)=0.0000000002394
cnt:1770000;x=-0.000840,abs(x-xbefore)=0.0000000002374
cnt:1780000;x=-0.000838,abs(x-xbefore)=0.0000000002354
cnt:1790000;x=-0.000836,abs(x-xbefore)=0.0000000002334
cnt:1800000;x=-0.000833,abs(x-xbefore)=0.0000000002315
cnt:1810000;x=-0.000831,abs(x-xbefore)=0.0000000002296
cnt:1820000;x=-0.000829,abs(x-xbefore)=0.0000000002277
cnt:1830000;x=-0.000826,abs(x-xbefore)=0.0000000002258
cnt:1840000;x=-0.000824,abs(x-xbefore)=0.0000000002240
cnt:1850000;x=-0.000822,abs(x-xbefore)=0.0000000002222
cnt:1860000;x=-0.000820,abs(x-xbefore)=0.0000000002204
cnt:1870000;x=-0.000818,abs(x-xbefore)=0.0000000002186
cnt:1880000;x=-0.000815,abs(x-xbefore)=0.0000000002169
cnt:1890000;x=-0.000813,abs(x-xbefore)=0.0000000002151
cnt:1900000;x=-0.000811,abs(x-xbefore)=0.0000000002134
cnt:1910000;x=-0.000809,abs(x-xbefore)=0.0000000002118
cnt:1920000;x=-0.000807,abs(x-xbefore)=0.0000000002101
cnt:1930000;x=-0.000805,abs(x-xbefore)=0.0000000002085
cnt:1940000;x=-0.000803,abs(x-xbefore)=0.0000000002069
cnt:1950000;x=-0.000801,abs(x-xbefore)=0.0000000002053
cnt:1960000;x=-0.000799,abs(x-xbefore)=0.0000000002037
cnt:1970000;x=-0.000797,abs(x-xbefore)=0.0000000002022
cnt:1980000;x=-0.000795,abs(x-xbefore)=0.0000000002006
cnt:1990000;x=-0.000793,abs(x-xbefore)=0.0000000001991
cnt:2000000;x=-0.000791,abs(x-xbefore)=0.0000000001976
cnt:2010000;x=-0.000789,abs(x-xbefore)=0.0000000001962
cnt:2020000;x=-0.000787,abs(x-xbefore)=0.0000000001947
cnt:2030000;x=-0.000785,abs(x-xbefore)=0.0000000001933
cnt:2040000;x=-0.000783,abs(x-xbefore)=0.0000000001919
cnt:2050000;x=-0.000781,abs(x-xbefore)=0.0000000001905
cnt:2060000;x=-0.000779,abs(x-xbefore)=0.0000000001891
cnt:2070000;x=-0.000777,abs(x-xbefore)=0.0000000001877
cnt:2080000;x=-0.000775,abs(x-xbefore)=0.0000000001863
cnt:2090000;x=-0.000773,abs(x-xbefore)=0.0000000001850
cnt:2100000;x=-0.000772,abs(x-xbefore)=0.0000000001837
cnt:2110000;x=-0.000770,abs(x-xbefore)=0.0000000001824
cnt:2120000;x=-0.000768,abs(x-xbefore)=0.0000000001811
cnt:2130000;x=-0.000766,abs(x-xbefore)=0.0000000001798
cnt:2140000;x=-0.000764,abs(x-xbefore)=0.0000000001786
cnt:2150000;x=-0.000762,abs(x-xbefore)=0.0000000001773
cnt:2160000;x=-0.000761,abs(x-xbefore)=0.0000000001761
cnt:2170000;x=-0.000759,abs(x-xbefore)=0.0000000001749
cnt:2180000;x=-0.000757,abs(x-xbefore)=0.0000000001737
cnt:2190000;x=-0.000755,abs(x-xbefore)=0.0000000001725
cnt:2200000;x=-0.000754,abs(x-xbefore)=0.0000000001713
cnt:2210000;x=-0.000752,abs(x-xbefore)=0.0000000001702
cnt:2220000;x=-0.000750,abs(x-xbefore)=0.0000000001690
cnt:2230000;x=-0.000749,abs(x-xbefore)=0.0000000001679
cnt:2240000;x=-0.000747,abs(x-xbefore)=0.0000000001667
cnt:2250000;x=-0.000745,abs(x-xbefore)=0.0000000001656
cnt:2260000;x=-0.000744,abs(x-xbefore)=0.0000000001645
cnt:2270000;x=-0.000742,abs(x-xbefore)=0.0000000001634
cnt:2280000;x=-0.000740,abs(x-xbefore)=0.0000000001624
cnt:2290000;x=-0.000739,abs(x-xbefore)=0.0000000001613
cnt:2300000;x=-0.000737,abs(x-xbefore)=0.0000000001603
cnt:2310000;x=-0.000736,abs(x-xbefore)=0.0000000001592
cnt:2320000;x=-0.000734,abs(x-xbefore)=0.0000000001582
cnt:2330000;x=-0.000732,abs(x-xbefore)=0.0000000001572
cnt:2340000;x=-0.000731,abs(x-xbefore)=0.0000000001562
cnt:2350000;x=-0.000729,abs(x-xbefore)=0.0000000001552
cnt:2360000;x=-0.000728,abs(x-xbefore)=0.0000000001542
cnt:2370000;x=-0.000726,abs(x-xbefore)=0.0000000001532
cnt:2380000;x=-0.000725,abs(x-xbefore)=0.0000000001522
cnt:2390000;x=-0.000723,abs(x-xbefore)=0.0000000001513
cnt:2400000;x=-0.000722,abs(x-xbefore)=0.0000000001504
cnt:2410000;x=-0.000720,abs(x-xbefore)=0.0000000001494
cnt:2420000;x=-0.000719,abs(x-xbefore)=0.0000000001485
cnt:2430000;x=-0.000717,abs(x-xbefore)=0.0000000001476
cnt:2440000;x=-0.000716,abs(x-xbefore)=0.0000000001467
cnt:2450000;x=-0.000714,abs(x-xbefore)=0.0000000001458
cnt:2460000;x=-0.000713,abs(x-xbefore)=0.0000000001449
cnt:2470000;x=-0.000711,abs(x-xbefore)=0.0000000001440
cnt:2480000;x=-0.000710,abs(x-xbefore)=0.0000000001431
cnt:2490000;x=-0.000709,abs(x-xbefore)=0.0000000001423
cnt:2500000;x=-0.000707,abs(x-xbefore)=0.0000000001414
cnt:2510000;x=-0.000706,abs(x-xbefore)=0.0000000001406
cnt:2520000;x=-0.000704,abs(x-xbefore)=0.0000000001397
cnt:2530000;x=-0.000703,abs(x-xbefore)=0.0000000001389
cnt:2540000;x=-0.000702,abs(x-xbefore)=0.0000000001381
cnt:2550000;x=-0.000700,abs(x-xbefore)=0.0000000001373
cnt:2560000;x=-0.000699,abs(x-xbefore)=0.0000000001365
cnt:2570000;x=-0.000697,abs(x-xbefore)=0.0000000001357
cnt:2580000;x=-0.000696,abs(x-xbefore)=0.0000000001349
cnt:2590000;x=-0.000695,abs(x-xbefore)=0.0000000001341
cnt:2600000;x=-0.000693,abs(x-xbefore)=0.0000000001333
cnt:2610000;x=-0.000692,abs(x-xbefore)=0.0000000001326
cnt:2620000;x=-0.000691,abs(x-xbefore)=0.0000000001318
cnt:2630000;x=-0.000689,abs(x-xbefore)=0.0000000001311
cnt:2640000;x=-0.000688,abs(x-xbefore)=0.0000000001303
cnt:2650000;x=-0.000687,abs(x-xbefore)=0.0000000001296
cnt:2660000;x=-0.000686,abs(x-xbefore)=0.0000000001289
cnt:2670000;x=-0.000684,abs(x-xbefore)=0.0000000001281
cnt:2680000;x=-0.000683,abs(x-xbefore)=0.0000000001274
cnt:2690000;x=-0.000682,abs(x-xbefore)=0.0000000001267
cnt:2700000;x=-0.000680,abs(x-xbefore)=0.0000000001260
cnt:2710000;x=-0.000679,abs(x-xbefore)=0.0000000001253
cnt:2720000;x=-0.000678,abs(x-xbefore)=0.0000000001246
cnt:2730000;x=-0.000677,abs(x-xbefore)=0.0000000001239
cnt:2740000;x=-0.000675,abs(x-xbefore)=0.0000000001233
cnt:2750000;x=-0.000674,abs(x-xbefore)=0.0000000001226
cnt:2760000;x=-0.000673,abs(x-xbefore)=0.0000000001219
cnt:2770000;x=-0.000672,abs(x-xbefore)=0.0000000001213
cnt:2780000;x=-0.000671,abs(x-xbefore)=0.0000000001206
cnt:2790000;x=-0.000669,abs(x-xbefore)=0.0000000001200
cnt:2800000;x=-0.000668,abs(x-xbefore)=0.0000000001193
cnt:2810000;x=-0.000667,abs(x-xbefore)=0.0000000001187
cnt:2820000;x=-0.000666,abs(x-xbefore)=0.0000000001180
cnt:2830000;x=-0.000665,abs(x-xbefore)=0.0000000001174
cnt:2840000;x=-0.000663,abs(x-xbefore)=0.0000000001168
cnt:2850000;x=-0.000662,abs(x-xbefore)=0.0000000001162
cnt:2860000;x=-0.000661,abs(x-xbefore)=0.0000000001156
cnt:2870000;x=-0.000660,abs(x-xbefore)=0.0000000001150
cnt:2880000;x=-0.000659,abs(x-xbefore)=0.0000000001144
cnt:2890000;x=-0.000658,abs(x-xbefore)=0.0000000001138
cnt:2900000;x=-0.000657,abs(x-xbefore)=0.0000000001132
cnt:2910000;x=-0.000655,abs(x-xbefore)=0.0000000001126
cnt:2920000;x=-0.000654,abs(x-xbefore)=0.0000000001120
cnt:2930000;x=-0.000653,abs(x-xbefore)=0.0000000001115
cnt:2940000;x=-0.000652,abs(x-xbefore)=0.0000000001109
cnt:2950000;x=-0.000651,abs(x-xbefore)=0.0000000001103
cnt:2960000;x=-0.000650,abs(x-xbefore)=0.0000000001098
cnt:2970000;x=-0.000649,abs(x-xbefore)=0.0000000001092
cnt:2980000;x=-0.000648,abs(x-xbefore)=0.0000000001087
cnt:2990000;x=-0.000647,abs(x-xbefore)=0.0000000001081
cnt:3000000;x=-0.000645,abs(x-xbefore)=0.0000000001076
cnt:3010000;x=-0.000644,abs(x-xbefore)=0.0000000001070
cnt:3020000;x=-0.000643,abs(x-xbefore)=0.0000000001065
cnt:3030000;x=-0.000642,abs(x-xbefore)=0.0000000001060
cnt:3040000;x=-0.000641,abs(x-xbefore)=0.0000000001055
cnt:3050000;x=-0.000640,abs(x-xbefore)=0.0000000001049
cnt:3060000;x=-0.000639,abs(x-xbefore)=0.0000000001044
cnt:3070000;x=-0.000638,abs(x-xbefore)=0.0000000001039
cnt:3080000;x=-0.000637,abs(x-xbefore)=0.0000000001034
cnt:3090000;x=-0.000636,abs(x-xbefore)=0.0000000001029
cnt:3100000;x=-0.000635,abs(x-xbefore)=0.0000000001024
cnt:3110000;x=-0.000634,abs(x-xbefore)=0.0000000001019
cnt:3120000;x=-0.000633,abs(x-xbefore)=0.0000000001014
cnt:3130000;x=-0.000632,abs(x-xbefore)=0.0000000001009
cnt:3140000;x=-0.000631,abs(x-xbefore)=0.0000000001005
cnt:3149791;x=-0.000630,abs(x-xbefore)=0.0000000001000

> 
> grad21(0.001,0.1,100000000)
cnt:1;x=0.001000,abs(x-xbefore)=0.0000000004000
cnt:10000;x=0.000996,abs(x-xbefore)=0.0000000003952
cnt:20000;x=0.000992,abs(x-xbefore)=0.0000000003906
cnt:30000;x=0.000988,abs(x-xbefore)=0.0000000003860
cnt:40000;x=0.000984,abs(x-xbefore)=0.0000000003815
cnt:50000;x=0.000981,abs(x-xbefore)=0.0000000003771
cnt:60000;x=0.000977,abs(x-xbefore)=0.0000000003728
cnt:70000;x=0.000973,abs(x-xbefore)=0.0000000003686
cnt:80000;x=0.000969,abs(x-xbefore)=0.0000000003645
cnt:90000;x=0.000966,abs(x-xbefore)=0.0000000003604
cnt:100000;x=0.000962,abs(x-xbefore)=0.0000000003564
cnt:110000;x=0.000959,abs(x-xbefore)=0.0000000003525
cnt:120000;x=0.000955,abs(x-xbefore)=0.0000000003486
cnt:130000;x=0.000952,abs(x-xbefore)=0.0000000003448
cnt:140000;x=0.000948,abs(x-xbefore)=0.0000000003411
cnt:150000;x=0.000945,abs(x-xbefore)=0.0000000003375
cnt:160000;x=0.000942,abs(x-xbefore)=0.0000000003339
cnt:170000;x=0.000938,abs(x-xbefore)=0.0000000003304
cnt:180000;x=0.000935,abs(x-xbefore)=0.0000000003269
cnt:190000;x=0.000932,abs(x-xbefore)=0.0000000003235
cnt:200000;x=0.000928,abs(x-xbefore)=0.0000000003202
cnt:210000;x=0.000925,abs(x-xbefore)=0.0000000003169
cnt:220000;x=0.000922,abs(x-xbefore)=0.0000000003137
cnt:230000;x=0.000919,abs(x-xbefore)=0.0000000003105
cnt:240000;x=0.000916,abs(x-xbefore)=0.0000000003074
cnt:250000;x=0.000913,abs(x-xbefore)=0.0000000003043
cnt:260000;x=0.000910,abs(x-xbefore)=0.0000000003013
cnt:270000;x=0.000907,abs(x-xbefore)=0.0000000002983
cnt:280000;x=0.000904,abs(x-xbefore)=0.0000000002954
cnt:290000;x=0.000901,abs(x-xbefore)=0.0000000002925
cnt:300000;x=0.000898,abs(x-xbefore)=0.0000000002897
cnt:310000;x=0.000895,abs(x-xbefore)=0.0000000002869
cnt:320000;x=0.000892,abs(x-xbefore)=0.0000000002842
cnt:330000;x=0.000889,abs(x-xbefore)=0.0000000002815
cnt:340000;x=0.000887,abs(x-xbefore)=0.0000000002788
cnt:350000;x=0.000884,abs(x-xbefore)=0.0000000002762
cnt:360000;x=0.000881,abs(x-xbefore)=0.0000000002736
cnt:370000;x=0.000878,abs(x-xbefore)=0.0000000002711
cnt:380000;x=0.000876,abs(x-xbefore)=0.0000000002686
cnt:390000;x=0.000873,abs(x-xbefore)=0.0000000002662
cnt:400000;x=0.000870,abs(x-xbefore)=0.0000000002638
cnt:410000;x=0.000868,abs(x-xbefore)=0.0000000002614
cnt:420000;x=0.000865,abs(x-xbefore)=0.0000000002590
cnt:430000;x=0.000863,abs(x-xbefore)=0.0000000002567
cnt:440000;x=0.000860,abs(x-xbefore)=0.0000000002544
cnt:450000;x=0.000857,abs(x-xbefore)=0.0000000002522
cnt:460000;x=0.000855,abs(x-xbefore)=0.0000000002500
cnt:470000;x=0.000852,abs(x-xbefore)=0.0000000002478
cnt:480000;x=0.000850,abs(x-xbefore)=0.0000000002457
cnt:490000;x=0.000848,abs(x-xbefore)=0.0000000002436
cnt:500000;x=0.000845,abs(x-xbefore)=0.0000000002415
cnt:510000;x=0.000843,abs(x-xbefore)=0.0000000002394
cnt:520000;x=0.000840,abs(x-xbefore)=0.0000000002374
cnt:530000;x=0.000838,abs(x-xbefore)=0.0000000002354
cnt:540000;x=0.000836,abs(x-xbefore)=0.0000000002334
cnt:550000;x=0.000833,abs(x-xbefore)=0.0000000002315
cnt:560000;x=0.000831,abs(x-xbefore)=0.0000000002296
cnt:570000;x=0.000829,abs(x-xbefore)=0.0000000002277
cnt:580000;x=0.000826,abs(x-xbefore)=0.0000000002258
cnt:590000;x=0.000824,abs(x-xbefore)=0.0000000002240
cnt:600000;x=0.000822,abs(x-xbefore)=0.0000000002222
cnt:610000;x=0.000820,abs(x-xbefore)=0.0000000002204
cnt:620000;x=0.000818,abs(x-xbefore)=0.0000000002186
cnt:630000;x=0.000815,abs(x-xbefore)=0.0000000002169
cnt:640000;x=0.000813,abs(x-xbefore)=0.0000000002151
cnt:650000;x=0.000811,abs(x-xbefore)=0.0000000002134
cnt:660000;x=0.000809,abs(x-xbefore)=0.0000000002118
cnt:670000;x=0.000807,abs(x-xbefore)=0.0000000002101
cnt:680000;x=0.000805,abs(x-xbefore)=0.0000000002085
cnt:690000;x=0.000803,abs(x-xbefore)=0.0000000002069
cnt:700000;x=0.000801,abs(x-xbefore)=0.0000000002053
cnt:710000;x=0.000799,abs(x-xbefore)=0.0000000002037
cnt:720000;x=0.000797,abs(x-xbefore)=0.0000000002022
cnt:730000;x=0.000795,abs(x-xbefore)=0.0000000002006
cnt:740000;x=0.000793,abs(x-xbefore)=0.0000000001991
cnt:750000;x=0.000791,abs(x-xbefore)=0.0000000001976
cnt:760000;x=0.000789,abs(x-xbefore)=0.0000000001962
cnt:770000;x=0.000787,abs(x-xbefore)=0.0000000001947
cnt:780000;x=0.000785,abs(x-xbefore)=0.0000000001933
cnt:790000;x=0.000783,abs(x-xbefore)=0.0000000001919
cnt:800000;x=0.000781,abs(x-xbefore)=0.0000000001905
cnt:810000;x=0.000779,abs(x-xbefore)=0.0000000001891
cnt:820000;x=0.000777,abs(x-xbefore)=0.0000000001877
cnt:830000;x=0.000775,abs(x-xbefore)=0.0000000001864
cnt:840000;x=0.000773,abs(x-xbefore)=0.0000000001850
cnt:850000;x=0.000772,abs(x-xbefore)=0.0000000001837
cnt:860000;x=0.000770,abs(x-xbefore)=0.0000000001824
cnt:870000;x=0.000768,abs(x-xbefore)=0.0000000001811
cnt:880000;x=0.000766,abs(x-xbefore)=0.0000000001798
cnt:890000;x=0.000764,abs(x-xbefore)=0.0000000001786
cnt:900000;x=0.000762,abs(x-xbefore)=0.0000000001773
cnt:910000;x=0.000761,abs(x-xbefore)=0.0000000001761
cnt:920000;x=0.000759,abs(x-xbefore)=0.0000000001749
cnt:930000;x=0.000757,abs(x-xbefore)=0.0000000001737
cnt:940000;x=0.000755,abs(x-xbefore)=0.0000000001725
cnt:950000;x=0.000754,abs(x-xbefore)=0.0000000001713
cnt:960000;x=0.000752,abs(x-xbefore)=0.0000000001702
cnt:970000;x=0.000750,abs(x-xbefore)=0.0000000001690
cnt:980000;x=0.000749,abs(x-xbefore)=0.0000000001679
cnt:990000;x=0.000747,abs(x-xbefore)=0.0000000001667
cnt:1000000;x=0.000745,abs(x-xbefore)=0.0000000001656
cnt:1010000;x=0.000744,abs(x-xbefore)=0.0000000001645
cnt:1020000;x=0.000742,abs(x-xbefore)=0.0000000001635
cnt:1030000;x=0.000740,abs(x-xbefore)=0.0000000001624
cnt:1040000;x=0.000739,abs(x-xbefore)=0.0000000001613
cnt:1050000;x=0.000737,abs(x-xbefore)=0.0000000001603
cnt:1060000;x=0.000736,abs(x-xbefore)=0.0000000001592
cnt:1070000;x=0.000734,abs(x-xbefore)=0.0000000001582
cnt:1080000;x=0.000732,abs(x-xbefore)=0.0000000001572
cnt:1090000;x=0.000731,abs(x-xbefore)=0.0000000001562
cnt:1100000;x=0.000729,abs(x-xbefore)=0.0000000001552
cnt:1110000;x=0.000728,abs(x-xbefore)=0.0000000001542
cnt:1120000;x=0.000726,abs(x-xbefore)=0.0000000001532
cnt:1130000;x=0.000725,abs(x-xbefore)=0.0000000001523
cnt:1140000;x=0.000723,abs(x-xbefore)=0.0000000001513
cnt:1150000;x=0.000722,abs(x-xbefore)=0.0000000001504
cnt:1160000;x=0.000720,abs(x-xbefore)=0.0000000001494
cnt:1170000;x=0.000719,abs(x-xbefore)=0.0000000001485
cnt:1180000;x=0.000717,abs(x-xbefore)=0.0000000001476
cnt:1190000;x=0.000716,abs(x-xbefore)=0.0000000001467
cnt:1200000;x=0.000714,abs(x-xbefore)=0.0000000001458
cnt:1210000;x=0.000713,abs(x-xbefore)=0.0000000001449
cnt:1220000;x=0.000711,abs(x-xbefore)=0.0000000001440
cnt:1230000;x=0.000710,abs(x-xbefore)=0.0000000001431
cnt:1240000;x=0.000709,abs(x-xbefore)=0.0000000001423
cnt:1250000;x=0.000707,abs(x-xbefore)=0.0000000001414
cnt:1260000;x=0.000706,abs(x-xbefore)=0.0000000001406
cnt:1270000;x=0.000704,abs(x-xbefore)=0.0000000001397
cnt:1280000;x=0.000703,abs(x-xbefore)=0.0000000001389
cnt:1290000;x=0.000702,abs(x-xbefore)=0.0000000001381
cnt:1300000;x=0.000700,abs(x-xbefore)=0.0000000001373
cnt:1310000;x=0.000699,abs(x-xbefore)=0.0000000001365
cnt:1320000;x=0.000697,abs(x-xbefore)=0.0000000001357
cnt:1330000;x=0.000696,abs(x-xbefore)=0.0000000001349
cnt:1340000;x=0.000695,abs(x-xbefore)=0.0000000001341
cnt:1350000;x=0.000693,abs(x-xbefore)=0.0000000001333
cnt:1360000;x=0.000692,abs(x-xbefore)=0.0000000001326
cnt:1370000;x=0.000691,abs(x-xbefore)=0.0000000001318
cnt:1380000;x=0.000689,abs(x-xbefore)=0.0000000001311
cnt:1390000;x=0.000688,abs(x-xbefore)=0.0000000001303
cnt:1400000;x=0.000687,abs(x-xbefore)=0.0000000001296
cnt:1410000;x=0.000686,abs(x-xbefore)=0.0000000001289
cnt:1420000;x=0.000684,abs(x-xbefore)=0.0000000001281
cnt:1430000;x=0.000683,abs(x-xbefore)=0.0000000001274
cnt:1440000;x=0.000682,abs(x-xbefore)=0.0000000001267
cnt:1450000;x=0.000680,abs(x-xbefore)=0.0000000001260
cnt:1460000;x=0.000679,abs(x-xbefore)=0.0000000001253
cnt:1470000;x=0.000678,abs(x-xbefore)=0.0000000001246
cnt:1480000;x=0.000677,abs(x-xbefore)=0.0000000001239
cnt:1490000;x=0.000675,abs(x-xbefore)=0.0000000001233
cnt:1500000;x=0.000674,abs(x-xbefore)=0.0000000001226
cnt:1510000;x=0.000673,abs(x-xbefore)=0.0000000001219
cnt:1520000;x=0.000672,abs(x-xbefore)=0.0000000001213
cnt:1530000;x=0.000671,abs(x-xbefore)=0.0000000001206
cnt:1540000;x=0.000669,abs(x-xbefore)=0.0000000001200
cnt:1550000;x=0.000668,abs(x-xbefore)=0.0000000001193
cnt:1560000;x=0.000667,abs(x-xbefore)=0.0000000001187
cnt:1570000;x=0.000666,abs(x-xbefore)=0.0000000001180
cnt:1580000;x=0.000665,abs(x-xbefore)=0.0000000001174
cnt:1590000;x=0.000663,abs(x-xbefore)=0.0000000001168
cnt:1600000;x=0.000662,abs(x-xbefore)=0.0000000001162
cnt:1610000;x=0.000661,abs(x-xbefore)=0.0000000001156
cnt:1620000;x=0.000660,abs(x-xbefore)=0.0000000001150
cnt:1630000;x=0.000659,abs(x-xbefore)=0.0000000001144
cnt:1640000;x=0.000658,abs(x-xbefore)=0.0000000001138
cnt:1650000;x=0.000657,abs(x-xbefore)=0.0000000001132
cnt:1660000;x=0.000655,abs(x-xbefore)=0.0000000001126
cnt:1670000;x=0.000654,abs(x-xbefore)=0.0000000001120
cnt:1680000;x=0.000653,abs(x-xbefore)=0.0000000001115
cnt:1690000;x=0.000652,abs(x-xbefore)=0.0000000001109
cnt:1700000;x=0.000651,abs(x-xbefore)=0.0000000001103
cnt:1710000;x=0.000650,abs(x-xbefore)=0.0000000001098
cnt:1720000;x=0.000649,abs(x-xbefore)=0.0000000001092
cnt:1730000;x=0.000648,abs(x-xbefore)=0.0000000001087
cnt:1740000;x=0.000647,abs(x-xbefore)=0.0000000001081
cnt:1750000;x=0.000645,abs(x-xbefore)=0.0000000001076
cnt:1760000;x=0.000644,abs(x-xbefore)=0.0000000001070
cnt:1770000;x=0.000643,abs(x-xbefore)=0.0000000001065
cnt:1780000;x=0.000642,abs(x-xbefore)=0.0000000001060
cnt:1790000;x=0.000641,abs(x-xbefore)=0.0000000001055
cnt:1800000;x=0.000640,abs(x-xbefore)=0.0000000001049
cnt:1810000;x=0.000639,abs(x-xbefore)=0.0000000001044
cnt:1820000;x=0.000638,abs(x-xbefore)=0.0000000001039
cnt:1830000;x=0.000637,abs(x-xbefore)=0.0000000001034
cnt:1840000;x=0.000636,abs(x-xbefore)=0.0000000001029
cnt:1850000;x=0.000635,abs(x-xbefore)=0.0000000001024
cnt:1860000;x=0.000634,abs(x-xbefore)=0.0000000001019
cnt:1870000;x=0.000633,abs(x-xbefore)=0.0000000001014
cnt:1880000;x=0.000632,abs(x-xbefore)=0.0000000001010
cnt:1890000;x=0.000631,abs(x-xbefore)=0.0000000001005
cnt:1899803;x=0.000630,abs(x-xbefore)=0.0000000001000
func3=function(t){
return(log(cosh(t)))
}

dffunc3=function(t){
return((sinh(t))/(cosh(t)))
}


grad3=function(x,rho,its){
	cnt=1
	for(i in 1:its){
		xbefore=x
		x=x-rho*dffunc3(x)
		if(cnt==1||0==cnt%%100){
			printf("cnt:%d;x=%f,abs(x-xbefore)=%.13f\n",cnt,x,abs(x-xbefore))
		}
		if(abs(x-xbefore)<=1.0e-8){
			break
		}
		cnt=cnt+1
	}

}
> grad3(5,0.01,100000)
cnt:1;x=4.990001,abs(x-xbefore)=0.0099990920426
cnt:100;x=4.000287,abs(x-xbefore)=0.0099934294467
cnt:200;x=3.002400,abs(x-xbefore)=0.0099517513467
cnt:300;x=2.017618,abs(x-xbefore)=0.0096590492535
cnt:400;x=1.113095,abs(x-xbefore)=0.0080797706330
cnt:500;x=0.479389,abs(x-xbefore)=0.0044934793548