数値積分公式

 投稿者:しばっち  投稿日:2019年10月13日(日)19時25分53秒
  MathMLを使用してWebブラウザー上で数式を美麗に表示します。

#213
数値積分公式をWebブラウザー上で表示させます。

OPTION ARITHMETIC RATIONAL
OPTION BASE 0
PUBLIC NUMERIC MAXLEVEL
LET MAXLEVEL=20
DIM X(1),Y(MAXLEVEL+1),L(MAXLEVEL+1)
OPEN #1:NAME "数値積分公式.html"
ERASE #1
PRINT #1:"<!DOCTYPE html>"
PRINT #1:"<html>"
PRINT #1:"<head>"
PRINT #1:"    <title>数値積分公式</title>"
PRINT #1:"    <script async src=";CHR$(34);"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML";CHR$(34);"></script>"
PRINT #1:"</head>"
PRINT #1:"<body>"
PRINT #1:"<h1>数値積分公式</h1>"
FOR N=1 TO MAXLEVEL
   FOR I=0 TO N
      CALL CLR(Y)
      LET P=1
      LET Y(0)=1
      FOR J=0 TO N
         IF I<>J THEN
            LET X(0)=-J
            LET X(1)=1
            CALL MUL(Y,X)
            LET P=P*(I-J)
         END IF
      NEXT J
      CALL INTEGRAL(Y)
      LET L(I)=HORNER(Y,N)/P
   NEXT I
   PRINT #1:"<math>"
   PRINT #1:"<msubsup>"
   PRINT #1:"    <mo>∫</mo>"
   PRINT #1:"    <mi>x0</mi>"
   PRINT #1:"    <mi>x";STR$(N);"</mi>"
   PRINT #1:"</msubsup>"
   PRINT #1:"<mi>f</mi>"
   PRINT #1:"<mfenced>"
   PRINT #1:"    <mi>x</mi>"
   PRINT #1:"</mfenced>"
   PRINT #1:"<mrow>"
   PRINT #1:"    <mi>d</mi>"
   PRINT #1:"    <mi>x</mi>"
   PRINT #1:"</mrow>"
   PRINT #1:"<mo>=</mo>"
   FOR I=0 TO N
      IF L(I)<0 THEN
         PRINT #1:"<mo>-</mo>"
      ELSE
         IF I<>0 THEN PRINT #1:"<mo>+</mo>"
      END IF
      IF ABS(DENOM(L(I)))=1 THEN
         PRINT #1:"    <mn>";STR$(ABS(L(I)));"</mn>"
      ELSE
         PRINT #1:"<mfrac>"
         PRINT #1:"    <mn>";STR$(ABS(NUMER(L(I))));"</mn>"
         PRINT #1:"    <mn>";STR$(ABS(DENOM(L(I))));"</mn>"
         PRINT #1:"</mfrac>"
      END IF
      PRINT #1:"<mi>h</mi>"
      PRINT #1:"<mi>f</mi>"
      PRINT #1:"<mfenced>"
      PRINT #1:"    <mi>x";STR$(I);"</mi>"
      PRINT #1:"</mfenced>"
   NEXT I
   PRINT #1:"</math>"
   PRINT #1:CHR$(60);CHR$(98);CHR$(114);CHR$(62)
   PRINT #1:CHR$(60);CHR$(98);CHR$(114);CHR$(62)
NEXT N
PRINT #1:"</body>"
PRINT #1:"</html>"
CLOSE #1
END

EXTERNAL SUB MUL(A(),B())
OPTION ARITHMETIC RATIONAL
OPTION BASE 0
DIM C(MAXLEVEL)
FOR I=0 TO 1
   FOR J=0 TO MAXLEVEL-I
      LET C(I+J)=C(I+J)+A(J)*B(I)
   NEXT J
NEXT I
CALL COPY(A,C)
END SUB

EXTERNAL FUNCTION HORNER(A(),XX)
OPTION ARITHMETIC RATIONAL
LET N=DIMCHECK(A)
LET Y=A(N)
FOR I=N-1 TO 0 STEP-1
   LET Y=Y*XX+A(I)
NEXT I
LET HORNER=Y
END FUNCTION

EXTERNAL SUB COPY(X(),Y())
OPTION ARITHMETIC RATIONAL
MAT X=Y
END SUB


EXTERNAL FUNCTION DIMCHECK(X())
OPTION ARITHMETIC RATIONAL
FOR N=MAXLEVEL TO 0 STEP-1
   IF X(N)<>0 THEN EXIT FOR
NEXT N
LET DIMCHECK=N
END FUNCTION

EXTERNAL SUB CLR(X())
OPTION ARITHMETIC RATIONAL
MAT X=ZER
END SUB

EXTERNAL SUB INTEGRAL(A())
OPTION ARITHMETIC RATIONAL
OPTION BASE 0
DIM B(MAXLEVEL)
FOR I=MAXLEVEL-1 TO 0 STEP-1
   LET B(I+1)=A(I)/(I+1)
NEXT I
CALL COPY(A,B)
END SUB
 

戻る