精留 ホームページプログラミング 


実習:連立非線形方程式 d1.htmlの作成 フォーム入力部と連立方程式を記述

<SCRIPT language=VBScript><!--
Dim vbCrLf : vbCrLf = chr(13) & chr(10)
Dim NN,NC,NCC,NI,NL1,NL,NK,NK1,NJ,NI1,ZW,ZW1,ZE,ZD
Dim ZA(), ZB(), ZX(), ZY(), NG(),F(), ZF1(), ZX1(), X()
Dim zF,R,al,q,FF,L,D,VD,W,I,XX,XXF,C1,C2,C3,C4
Sub A_onClick
txtsolution.value=""
document.chartApplet.clear
chartApplet.setFontSize 12
chartApplet.setColor 255,255,200
chartApplet.fillRect 30,10,300,300
chartApplet.setColor 0,0,0
NN=16
ReDim ZA(NN,NN), ZB(NN), ZX(NN), ZY(NN), NG(NN) 
ReDim F(NN), ZF1(NN), ZX1(NN), X(NN)
zF=ValzF.value
R=ValR.value
al=Valal.value
q=Valq.value
FF=1.0
D=ValD.value
W=1-D
L=R*D
VD=L-W+q*FF
ValVD.value=VD
C1 = L / (L + D)
C2 = D / (L + D)
C3 = (L + q * FF) / (L + q * FF - W)
C4 = W / (L + q * FF - W)

FOR NI =1 TO NN
	ZX1(NI)=(18-NI)*0.05
NEXT
NL1=50
ZE=0.00001
ZD=0.001
NL=0
NCC=0
Do Until NCC=NN
NL=NL+1
ValNL.value=NL
IF NL=NL1 Then 
	Exit Do
End If
FOR NI = 1 TO NN
	X(NI) = ZX1(NI)
NEXT
Call Sub4000 
FOR NI = 1 TO NN
	ZF1(NI) = F(NI)
NEXT 
Call Sub3000
FOR NI = 1 TO NN
	NG(NI) = NI
NEXT
Call Sub1000 
FOR NI = 1 TO NN 
	NJ = NG(NI)
	ZB(NI) = -ZF1(NJ)
NEXT
Call Sub2000 
NC =0
FOR NI = 1 TO NN 
	ZW = X(NI) 
	ZX1(NI) = ZX1(NI) + ZW 
	IF ABS(ZW) < ZE OR ABS(ZW) < ZE * ABS(ZX1(NI)) THEN 
	NC = NC+1
	End If 
NEXT
NCC=NC
Loop
txtsolution.value=" xD=x1=y2= " & ZX1(1) & vbCrLf 
txtsolution.value=txtsolution.value & " x2= " & ZX1(2) & " y3= " & ZX1(3) & vbCrLf
txtsolution.value=txtsolution.value & " x3= " & ZX1(4) & " y4= " & ZX1(5) & vbCrLf
txtsolution.value=txtsolution.value & " x4= " & ZX1(6) & " y5= " & ZX1(7) & vbCrLf
txtsolution.value=txtsolution.value & " x5= " & ZX1(8) & " y6= " & ZX1(9) & vbCrLf
txtsolution.value=txtsolution.value & " x6= " & ZX1(10)& " y7= " & ZX1(11) & vbCrLf
txtsolution.value=txtsolution.value & " x7= "& ZX1(12) & " y8= " & ZX1(13 )& vbCrLf
txtsolution.value=txtsolution.value & " x8= "& ZX1(14) & " y9= " & ZX1(15) & vbCrLf
txtsolution.value=txtsolution.value & " xW= " & ZX1(16)
chartApplet.drawLine 30, 10, 330, 10
chartApplet.drawLine 30, 310, 330, 310
chartApplet.drawLine 330, 10, 330, 310
chartApplet.drawLine 30, 10, 30, 310
chartApplet.drawLine 30, 310, 330, 10
chartApplet.drawLine 60, 300, 60, 310
chartApplet.drawLine 90, 300, 90, 310
chartApplet.drawLine 120, 300, 120, 310
chartApplet.drawLine 150, 300, 150, 310
chartApplet.drawLine 180, 300, 180, 310
chartApplet.drawLine 210, 300, 210, 310
chartApplet.drawLine 240, 300, 240, 310
chartApplet.drawLine 270, 300, 270, 310
chartApplet.drawLine 300, 300, 300, 310
chartApplet.drawString "0            0.2            0.4           0.6            0.8             1", 28, 322
chartApplet.drawLine 30, 40,40, 40
chartApplet.drawLine 30, 70,40, 70
chartApplet.drawLine 30, 100,40, 100
chartApplet.drawLine 30, 130,40, 130
chartApplet.drawLine 30, 160,40, 160
chartApplet.drawLine 30, 190,40, 190
chartApplet.drawLine 30, 220,40, 220
chartApplet.drawLine 30, 250,40, 250
chartApplet.drawString "1", 15, 15
chartApplet.drawString "0.8", 10, 75
chartApplet.drawString "0.6", 10, 135
chartApplet.drawString "0.4", 10, 195 
chartApplet.drawString "0.2", 10, 255
chartApplet.drawString "0", 15, 315
chartApplet.drawString "y", 5, 165
chartApplet.drawString "x", 170, 325
chartApplet.setColor 0,0,255
XXF=0
For I=5 to 100 step 5
XX=al*(I/100)/(1+(al-1)*(I/100))
chartApplet.drawline (I-5)*3+30, 310-XXF*300 ,I*3+30,310-XX*300
XXF=XX
next
chartApplet.setColor 0,0,0
chartApplet.drawline ZX1(16)*300+30, 310-0*300 ,ZX1(16)*300+30,310-ZX1(15)*300
chartApplet.drawline ZX1(16)*300+30,310-ZX1(15)*300 ,ZX1(14)*300+30,310-ZX1(15)*300
chartApplet.drawline ZX1(14)*300+30,310-ZX1(15)*300, ZX1(14)*300+30,310-ZX1(13)*300 
chartApplet.drawline ZX1(14)*300+30,310-ZX1(13)*300, ZX1(12)*300+30,310-ZX1(13)*300 
chartApplet.drawline ZX1(12)*300+30,310-ZX1(13)*300, ZX1(12)*300+30,310-ZX1(11)*300 
chartApplet.drawline ZX1(12)*300+30,310-ZX1(11)*300, ZX1(10)*300+30,310-ZX1(11)*300
chartApplet.drawline ZX1(10)*300+30,310-ZX1(11)*300, ZX1(10)*300+30,310-ZX1(9)*300
chartApplet.drawline ZX1(10)*300+30,310-ZX1(9)*300, ZX1(8)*300+30,310-ZX1(9)*300
chartApplet.drawline ZX1(8)*300+30,310-ZX1(9)*300, ZX1(8)*300+30,310-ZX1(7)*300
chartApplet.drawline ZX1(8)*300+30,310-ZX1(7)*300, ZX1(6)*300+30,310-ZX1(7)*300
chartApplet.drawline ZX1(6)*300+30,310-ZX1(7)*300, ZX1(6)*300+30,310-ZX1(5)*300
chartApplet.drawline ZX1(6)*300+30,310-ZX1(5)*300, ZX1(4)*300+30,310-ZX1(5)*300
chartApplet.drawline ZX1(4)*300+30,310-ZX1(5)*300, ZX1(4)*300+30,310-ZX1(3)*300
chartApplet.drawline ZX1(4)*300+30,310-ZX1(3)*300, ZX1(2)*300+30,310-ZX1(3)*300
chartApplet.drawline ZX1(2)*300+30,310-ZX1(3)*300, ZX1(2)*300+30,310-ZX1(1)*300
chartApplet.drawline ZX1(2)*300+30,310-ZX1(1)*300, ZX1(1)*300+30,310-ZX1(1)*300
chartApplet.drawline ZX1(1)*300+30,310-ZX1(1)*300, ZX1(1)*300+30,310-0*300
chartApplet.setColor 255,0,0
chartApplet.drawline ZX1(1)*300+30,310-ZX1(1)*300, ZX1(8)*300+30,310-ZX1(9)*300
chartApplet.drawline ZX1(8)*300+30,310-ZX1(9)*300, ZX1(16)*300+30,310-ZX1(16)*300
chartApplet.setColor 0,255,0
chartApplet.drawline ZX1(8)*300+30,310-ZX1(9)*300, zF*300+30,310-zF*300
chartApplet.setColor 0,0,0
chartApplet.drawline zF*300+30,310-zF*300, zF*300+30,310-0*300
End Sub
Sub Sub1000
FOR NK = 1 TO NN-1
ZW = ABS(ZA(NK, NK))
NK1 = NK
FOR NI = NK+1 TO NN
	ZW1 = ABS(ZA(NI, NK))
	IF ZW1 > ZW THEN
	ZW = ZW1
	NK1 = NI
	End If
NEXT
IF NK <> NK1 THEN
FOR NJ = 1 TO NN
ZW = ZA(NK, NJ)
ZA(NK, NJ) = ZA(NK1, NJ)
ZA(NK1, NJ) = ZW 
NEXT 
NI1 = NG(NK)
NG(NK) = NG(NK1)
NG(NK1) = NI1 
End If 
ZW = ZA(NK, NK)
FOR NI = NK + 1 TO NN 
	ZA(NI, NK) = ZA(NI, NK) / ZW 
	FOR NJ = NK + 1 TO NN 
		ZA(NI, NJ) = ZA(NI,NJ) - ZA(NI,NK) * ZA(NK, NJ) 
	NEXT
NEXT
NEXT
End Sub
Sub Sub2000
ZY(1) = ZB(1)
FOR NI = 2 TO NN
	ZW = ZB(NI) 
	FOR NK = 1 TO NI - 1 
		ZW = ZW - ZA(NI,NK) * ZY(NK) 
	NEXT 
	ZY(NI) = ZW 
NEXT
X(NN) = ZY(NN) / ZA(NN, NN) 
FOR NI=NN-1 TO 1 STEP -1
	ZW = ZY(NI) 
	FOR NK = NI+1 TO NN 
		ZW = ZW - ZA(NI,NK) * X(NK) 
	NEXT
	X(NI) = ZW / ZA(NI, NI) 
NEXT
End Sub
Sub Sub3000
FOR NJ = 1 TO NN
IF NJ <>1 Then
	X(NJ - 1) = ZX1(NJ - 1) 
End If
X(NJ) = X(NJ) + ZD 
Call Sub4000 
FOR NI = 1 TO NN 
	ZA(NI, NJ) = (F(NI) - ZF1(NI)) / ZD 
NEXT
NEXT
End Sub
Sub Sub4000
' X(1):y2=x1=xD X(2):x2 X(3):y3 X(4):x3 X(5):y4 X(6):x4 X(7):y5 X(8):x5 
' X(9):y6 X(10):x6 X(11):y7 X(12):x7 X(13):y8 X(14):x8 X(15):y9 X(16):xW
F(1) = D * X(1) + W * X(16) - FF * zF
F(2) = X(1) - al * X(2) / (1 + (al - 1) * X(2))
F(3) = C1 * X(2) + C2 * X(1) - X(3)
F(4) = X(3) - al * X(4) / (1 + (al - 1) * X(4))
F(5) = C1 * X(4) + C2 * X(1) - X(5)
F(6) = X(5) - al * X(6) / (1 + (al - 1) * X(6))
F(7) = C1 * X(6) + C2 * X(1) - X(7)
F(8) = X(7) - al * X(8) / (1 + (al - 1) * X(8))
F(9) = C1 * X(8) + C2 * X(1) - X(9)
F(10) = X(9) - al * X(10) / (1 + (al - 1) * X(10))
F(11) = C3 * X(10) - C4 * X(16) - X(11)
F(12) = X(11) - al * X(12) / (1 + (al - 1) * X(12))
F(13) = C3 * X(12) - C4 * X(16) - X(13)
F(14) = X(13) - al * X(14) / (1 + (al - 1) * X(14))
F(15) = C3 * X(14) - C4 * X(16) - X(15)
F(16) = X(15) - al * X(16) / (1 + (al - 1) * X(16))
End Sub
--></SCRIPT>