' program DIFF-LI2.bas 'nomainwin DIM C(102,102) OPEN "c:\kpdat" FOR OUTPUT AS #1 WindowWidth = 590 : WindowHeight = 500'470 270 ' left top length hight StaticText #w.1, "A:" ,140, 10, 45, 20 StaticText #w.2, "B:" ,200, 10, 45, 20 StaticText #w.3, "C:" ,260, 10, 45, 20 StaticText #w.4, "D:" ,320, 10, 45, 20 STATICTEXT #w.5, "E:" ,380, 10, 45, 20 staticText #w.6, "Xstart:" ,380, 85, 40, 20 StaticText #w.7, "Ystart:" ,380, 115 ,40, 20 StaticText #w.8, "dY/dX:" ,380, 145 ,40, 20 StaticText #w.9, "Xend:" ,470, 85, 30, 20 StaticText #w.10, "Yend:" ,470, 115, 30, 20 StaticText #w.11, "dY/dX:" ,465, 145 ,35, 20 StaticText #w.12, " Finite Step:" ,160, 120, 50, 40 StaticText #w.status1, "", 60, 50 , 350, 20'diffeq StaticText #w.status3, "", 10, 30, 40, 40'START HERE StaticText #w.status5, "", 400, 175, 200, 20'recnum StaticText #w.status6, "", 5, 175, 70, 20'recnum StaticText #w.status9, "", 10, 70, 100, 30 TextBox #w.eq, 100, 80, 270, 20 TextBox #w.n, 120, 30, 50, 20 TextBox #w.n1, 180, 30, 50, 20 TextBox #w.t, 240, 30, 50, 20 TextBox #w.xx, 300, 30, 50, 20 TextBox #w.comp1, 360, 30, 50, 20 ' TextBox #w.mol1, 460, 65, 30, 20 TextBox #w.comp2, 420, 80, 40, 20'xin TextBox #w.mol2, 420, 110, 40, 20'yin TextBox #w.comp3, 420, 140, 40, 20'dy/dx in TextBox #w.mol3, 500, 80, 40, 20'xout TextBox #w.mol4, 200, 120, 40, 20'runge step TextBox #w.comp4, 500, 110, 40, 20'yout TextBox #w.comp5, 500, 140, 40, 20'dy/dx out ' TextBox #w.mol5, 620, 65, 30, 20 ' TextBox #w.comp6, 660, 35, 30, 20 ' TextBox #w.mol6, 660, 65, 30, 20 Button #w.c1, "Reset", [reset], UL, 30, 10, 50, 30 ' Button #w.c1, "Continue1", [continue1], UL, 355, 30, 60, 30 ' Button #w.c2, "Continue2", [continue2], UL, 695, 30, 60, 30 Button #w.c3, "Calc", [calc], UL, 280,120, 60, 30 Button #w.exit, "Close", [close.w], UL, 500,20, 40, 30 Button #w.add, "Add New at end", [add.rec], UL, 80,170, 90, 25 Button #w.upd, "Update present", [update.rec], UL, 180,170, 90, 25 Button #w.prv, "Previous", [prev.rec], UL, 280,170, 50, 25 Button #w.next, "Next", [next.rec], UL, 340,170, 50, 25 TEXTEDITOR #w.res, 10,200, 550,250'HEIGHT ' TEXTeditor #w.conf, 400,90, 280, 70'HEIGHT ' TEXTeditor #w.form, 10, 80, 370, 80'HEIGHT open "DIFFERENTIAL EQUATION, TWO POINT VALUE, FINITE ELEMENT" for dialog as #w print #w, "trapclose [close.w]" print #w.n, "!setfocus" 'print #w.status3,"START HERE" ' **** Adress file **** axx=6 'prompt " Choose Indata file(kplib) number (1-10)";axx open "DIFFEQ";axx;".dat" for random as #vcl len=128 print #w.status9, "Indata file: DIFFEQ";axx;".dat " print #w.status1,"D2Y/DX2 + A*DY/DX + B*Y + C*Y*X^D + E = 0" Field #vcl, _ 60 as EQ$, _ 5 as A11, _ 5 as B11, _ 5 as C11, _ 5 as D11, _ 5 as mol1,_ 6 as YS,_ 5 as XE,_ 5 as N1,_ 5 as YE,_ 5 as DERE,_ 5 as E11,_ 5 as XS,_ 6 as DER,_ 1 as RES, rec= lof(#vcl) / 128 print #w.status6, "Next add at ";rec+1 for I=1 to rec get #vcl,I print #w.res, " ";EQ$ next I print #w.eq,"!font Times_New_Roman 10 bold" print #w.n,"!font Times_New_Roman 10 bold" print #w.n1,"!font Times_New_Roman 10 bold" print #w.t,"!font Times_New_Roman 10 bold" print #w.xx,"!font Times_New_Roman 10 bold" print #w.comp1,"!font Times_New_Roman 10 bold" print #w.comp2,"!font Times_New_Roman 10 bold" print #w.comp3,"!font Times_New_Roman 10 bold" print #w.comp4,"!font Times_New_Roman 10 bold" print #w.comp5,"!font Times_New_Roman 10 bold" print #w.mol2,"!font Times_New_Roman 10 bold" print #w.mol3,"!font Times_New_Roman 10 bold" 'print #w.res,"!font Courier_New 8 bold " print #w.res,"!font Times_New_Roman 12 bold" goto [reset] goto [loop] PRINT" " [validate]'subroutine valid = 1 print #w.eq, "!contents?" input #w.eq, EQ$ if len(EQ$)>60 then notice "Error!" +chr$(13)+"Allowed string=60, Actual=";len(EQ$) valid=0 return end if print #w.n, "!contents?" input #w.n, A11 print #w.n1, "!contents?" input #w.n1, B11 print #w.t, "!contents?" input #w.t, C11 print #w.xx, "!contents?" input #w.xx, D11 print #w.comp1, "!contents?" input #w.comp1,E11 print #w.comp2, "!contents?" input #w.comp2,XS print #w.comp3, "!contents?" input #w.comp3,DER print #w.comp4, "!contents?" input #w.comp4,YE print #w.comp5, "!contents?" input #w.comp5,DERE 'print #w.comp6, "!contents?" 'input #w.comp6,comp6 'print #w.mol1, "!contents?" 'input #w.mol1,mol1 print #w.mol2, "!contents?" input #w.mol2,YS print #w.mol3, "!contents?" input #w.mol3,XE print #w.mol4, "!contents?" input #w.mol4,N1 'print #w.mol5, "!contents?" 'input #w.mol5,mol5 'print #w.mol6, "!contents?" 'input #w.mol6,mol6 return [add.rec] gosub [validate] if valid = 0 then [loop] recNum = lof(#vcl) / 128 + 1 ' calc location of next record put #vcl, recNum print #w.res, "!cls" print #w.status5, " recNum:"; recNum;" has been added at ";recNum rec= lof(#vcl) / 128 print #w.status6, "Next add at ";rec+1 goto [loop] [update.rec] gosub [validate] if valid = 0 then [loop] put #vcl, recNum 'print #w.res, "!cls" print #w.status5, " recNum: ";recNum;" has been updated at ";recNum goto [loop] [display.rec]'subroutine print #w.eq,EQ$ print #w.n, A11 print #w.n1,B11 print #w.t, C11 print #w.xx,D11 'print #w.mol1,mol1 print #w.mol2,YS print #w.mol3,XE print #w.mol4,N1 'print #w.mol5,mol5 'print #w.mol6,mol6 print #w.comp1,E11 print #w.comp2,XS print #w.comp3,DER print #w.comp4,YE print #w.comp5,DERE 'print #w.comp6,comp6 return [prev.rec] if recNum > 1 then recNum = recNum - 1 get #vcl, recNum yy1=lof(#vcl) / 128 print #w.status5, "record-Nr=";recNum;": End of file at ";yy1 else print #w.status5, " Start of file: End of file at ";yy1 end if gosub [display.rec] goto [loop] [next.rec] if recNum < lof(#vcl) / 128 then recNum = recNum + 1 get #vcl, recNum yy=lof(#vcl) / 128 print #w.status5, "record-Nr=";recNum;": End of file at ";yy else print #w.status5, "End of file: Next add at ";recNum+1 end if gosub [display.rec] 'print #w.conf, "press next again or cont1" goto [loop] [reset] print #w.n, "0"; print #w.n1, "0" ; print #w.t, "0" ; print #w.xx, "0" ; print #w.comp1, "0" ; 'print #w.mol1, "0" ; print #w.comp2, "0" ; print #w.mol2, "0" ; print #w.comp3, "0" ; print #w.mol3, "0" ; print #w.comp4, "0" ; print #w.mol4, "0" ; print #w.comp5, "0" ; 'print #w.mol5, "0" ; 'print #w.comp6, "0" ; 'print #w.mol6, "0" ; 'print #w.conf, "!cls" ; ' print #w.form, "!cls" ; print #w.eq, " " ; print #w.res," Start: Press next to get saved data" print #w.res," Change or insert new data, followed by UPDATE or ADD" print #w.res," ADD places the data at the end of the file" print #w.res," Play with the buttons so you learn how to preserve your data" goto [loop] [loop] input var$ goto [loop] [calc] '************* INPUT DATA INFORMATION ******* 'A11=A(INPUT WINDOW) B11=B C11=C D11=D E11=E 'XS=XSTART(INPUT WINDOW) XE=XEND YS= YSTART 'DY/DX(START)=DER DY/DX(END)=DERE 'N1=FINITE STEP '************************************************** ' INDATA M=N1-1' M=NUMBER OF EQUATIONS A=.25 B=8 xin =XS xend =XE yin =YS yend =YE uin =DER uend=DERE pp=xend-xin DX=pp/(M+1) CC=E11*(-1)*DX^2 'END INDATA print XS;" ";YS ' SETUP OF COEFF. MATRIX ' C(i,j) ' j= 1 2 3 4 5 6 ' 'i=1 A 1 Y1 = CC ' 2 1 A 1 Y2 ' 3 1 A 1 Y3 ' 4 1 A 1 Y4 ' 5 1 A Y5 n1=M 'FIRST EQUATION AT n1=0 for i=1 to n1 C(i,n1+1)=CC 'CONSTANT TERM next i C(1,n1+1)=CC-YS C(n1,n1+1)=CC-YE for i=1 to n1-1 C(i,i+1)=1 'UPPER 1 next i for i=1 to n1 C(i,i)=B11*DX^2+ A11*DX + C11*DX^(2)*(DX*i)^D-2 'DIAGONAL next i for i=2 to n1 C(i,i-1)=1-A11*DX 'LOWER 1 next i 'LAST EQUATION AT n1 giving DY/DX print #w.res,"" CONFIRM" Shooting at DY/DX=yes at Y=no";answer$ IF answer$="yes" THEN C(n1,n1+1)=DERE*DX*2 C(n1,n1)=3 C(n1,n1-1)=4*(-1) C(n1,n1-2)=1 PRINt #w.res,"Shooting towards dy/dx at end";" steps=";N1 else PRINt #w.res,"Shooting towards Yend ";" steps= ";N1 END IF print DERE ' END OF SETUP print #w.res,EQ$ print #w.res,"XSTART=";XS;" XEND=";XE;" YSTART=";YS;" YEND=";YE PRINT #w.res," DY/DX(END)=";DERE;" DY/DX(START)=";DER print #w.res," X Y DY/DX(appr)" print 0 ;" "; yin 'print #w.res," "; 0 ;" "; yin gosub [gauss] print n1+1;" ";yend 'print #w.res," "; pp/(n1+1)*(n1+1)+XS;" ";yend;" ";(C(n1+1,N)-C(n1,N))/DX print "analytical solution at x=5 ,71.9429" print #w.res,"Problem with repeated calculations; clear memory by closing and start new" print #w.res, "Use < 50 steps as a rule in the iteration. " print #w.res,"The values obtained are not very accurate." print #w.res,"Increasing the number of steps creates rounding off error" GOTO [loop] [close.w] close #w :CLOSE #1:close #vcl print" press ENTER to close" input r$ print" *** end ***" end [gauss] N=M+1 FOR J=1 TO M FOR I=J TO M IF C(I,J)<>0 then FOR K=1 TO N X=C(J,K) C(J,K)=C(I,K) C(I,K)=X NEXT K end if NEXT I C(J,J)=C(J,J) Y=1/C(J,J) FOR K=1 TO N C(J,K)=Y*C(J,K) NEXT K FOR I=1 TO M IF I=J GOTO 41 Y=C(I,J)*(-1) FOR K=1 TO N C(I,K)=C(I,K)+Y*C(J,K) NEXT K 41 NEXT I NEXT J FOR J=1 TO M if J<>1 then PRINT #w.res,using("##.##",J/(n1+1)*pp+XS);" ";C(J,N);" ";(C(J,N)-C(J-1,N))/DX if J=1 then print #w.res,using("##.##",J/(n1+1)*pp+XS);" ";C(J,N) PRINT using("##.##",J/(n1+1)*pp+XS);" ";C(J,N);" ";(C(J,N)-C(J-1,N))/DX REM NEXT J return