1-masalaning yechimini Basic dasturlash tilida topish:
(2.42) formula asosida
‘Monte-Karlo usulida ikkilangan integralni hisoblash
DEF FNF (x, y) = x + 2 * y #2 o`zgaruvchili funksiya ko`rinishi
DEF FNF1 (x) = x / 2 #integral quyi chegarasi
DEF FNF2 (x) = x #integral yuqori chegarasi
DIM x(100), xt(100), y(100), y1(100), y2(100), yt(100)
n1 = 0: INPUT "N="; N: INPUT "AC = FNF1(a): D = FNF2(b): PRINT "c="; C, " b="; b
'INPUT "CFOR i = 1 TO N
X(I) = A + (B - A) * RND(1): y(i) = C + (D - C) * RND(1)
y1(i) = FNF1(x(i)): y2(i) = FNF2(x(i)): NEXT i
PRINT " xi yi y1(i) y2(i) FNF(xi, yi)"
FOR i = 1 TO N
PRINT USING "###.#####"; x(i); y(i); y1(i); y2(i); FNF(x(i), y(i)): NEXT i
FOR i = 1 TO N
IF y1(i) < y(i) AND y(i) < y2(i) THEN n1 = n1 + 1: xt(n1) = x(i): yt(n1) = y(i)
NEXT i: PRINT "N1="; n1
PRINT " xt(i) yt(i) FNF(xt, yt)"
FOR i = 1 TO n1
PRINT USING "###.#####"; xt(i); yt(i); FNF(xt(i), yt(i))
S = S + FNF(xt(i), yt(i))
NEXT i
S1 = (B - A) * (D - C) * S / N: PRINT " S1="; s1
END
N=? 10
Ac= 0 d= 1
xi yi y1(i) y2(i) FNF(xi, yi)
0.70555 0.53342 0.35277 0.70555 1.77240
0.57952 0.28956 0.28976 0.57952 1.15864
0.30195 0.77474 0.15097 0.30195 1.85143
0.01402 0.76072 0.00701 0.01402 1.53546
0.81449 0.70904 0.40725 0.81449 2.23257
0.04535 0.41403 0.02268 0.04535 0.87342
0.86262 0.79048 0.43131 0.86262 2.44358
0.37354 0.96195 0.18677 0.37354 2.29744
0.87145 0.05624 0.43572 0.87145 0.98392
0.52487 0.76711 0.26243 0.52487 2.05909
0.05350 0.59246 0.02675 0.05350 1.23842
0.46870 0.29817 0.23435 0.46870 1.06503
0.62270 0.64782 0.31135 0.62270 1.91834
0.26379 0.27934 0.13190 0.26379 0.82248
0.82980 0.82460 0.41490 0.82980 2.47901
0.58916 0.98609 0.29458 0.58916 2.56135
0.91096 0.22687 0.45548 0.91096 1.36470
0.69512 0.98000 0.34756 0.69512 2.65512
0.24393 0.53387 0.12197 0.24393 1.31168
N1= 5
xt(i) yt(i) FNF(xt, yt)
0.70555 0.53342 1.77240
0.81449 0.70904 2.23257
0.86262 0.79048 2.44358
0.46870 0.29817 1.06503
0.82980 0.82460 2.47901
S1= 0.4941289
Yuqoridan ko`rinib turibdiki aniq yechim y=0.417 va biz Basic tilida hisoblab topgan yechimimiz s1=0.494. endi xatolikni baholab olamiz:
=(s1-y)/y=(0.494-0.417)/0.417=0.18=18% Demak, xatolik 18% , bundan ko`rinib turibdiki biz random orqali tanlab olgan ixtiyoriy 5ta x, y o`zgaruvchilarimiz hisoblashda katta xatolikni keltirib chiqarar ekan.
Do'stlaringiz bilan baham: |