SIN倍角公式

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

https://decimalbasic.ninja-web.net/log/article/b/basic/104/nkozlh/nkozlh.html
SIN倍角公式をWebブラウザー上で表示させます。

OPTION ARITHMETIC RATIONAL
OPTION BASE 0
LET MAXLEVEL=50
DIM S(MAXLEVEL,MAXLEVEL)
OPEN #1:NAME "SIN倍角公式.html"
ERASE #1
PRINT #1:"<!DOCTYPE html>"
PRINT #1:"<html>"
PRINT #1:"<head>"
PRINT #1:"    <title>SIN倍角公式</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>SIN倍角公式</h1>"
FOR N=2 TO MAXLEVEL
   PRINT #1:"<math>"
   PRINT #1:"<mi>sin</mi>"
   PRINT #1:"<mn>";STR$(N);"</mn>"
   PRINT #1:"<mi>θ</mi>"
   PRINT #1:"<mo>=</mo>"
   FOR K=0 TO N/2
      IF N-2*K-1>=0 THEN LET S(2*K+1,N-2*K-1)=(-1)^K*COMB(N,2*K+1)
   NEXT K
   CALL DISPLAYSIN(S,N,#1)
   PRINT #1:"</math>"
   PRINT #1:CHR$(60);CHR$(98);CHR$(114);CHR$(62)
   MAT S=ZER
NEXT N
PRINT #1:"</body>"
PRINT #1:"</html>"
CLOSE #1
END

EXTERNAL SUB DISPLAYSIN(SINE(,),K,#1)
OPTION ARITHMETIC RATIONAL
DIM S(0 TO 2)
LET S(0)=1
LET S(2)=-1
FOR L=K TO 2 STEP-1
   FOR I=0 TO K-2
      FOR J=0 TO 2
         LET SINE(I+J,L-2)=SINE(I+J,L-2)+SINE(I,L)*S(J)
      NEXT J
      LET SINE(I,L)=0
   NEXT I
NEXT L
FOR I=K TO 0 STEP-1
   FOR J=K TO 0 STEP-1
      IF SINE(I,J)<>0 THEN
         IF FL=0 THEN
            IF SINE(I,J)<0 THEN PRINT #1:"<mo>-</mo>"
         END IF
         IF FL=1 THEN
            IF SINE(I,J)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
         END IF
         IF I>1 THEN
            PRINT #1:"<mn>";STR$(ABS(SINE(I,J)));"</mn>"
            PRINT #1:"<msup>"
            PRINT #1:"    <mi>sin</mi>"
            PRINT #1:"    <mn>";STR$(I);"</mn>"
            PRINT #1:"</msup>"
            PRINT #1:"    <mi>θ</mi>"
         ELSEIF I=1 THEN
            PRINT #1:"<mn>";STR$(ABS(SINE(I,J)));"</mn>"
            PRINT #1:"<mi>sin</mi>"
            PRINT #1:"    <mi>θ</mi>"
         END IF
         IF J>1 THEN
            PRINT #1:"<msup>"
            PRINT #1:"    <mi>cos</mi>"
            PRINT #1:"    <mn>";STR$(J);"</mn>"
            PRINT #1:"</msup>"
            PRINT #1:"    <mi>θ</mi>"
         ELSEIF J=1 THEN
            PRINT #1:"<mi>cos</mi>"
            PRINT #1:"    <mi>θ</mi>"
         END IF
         LET FL=1
      END IF
   NEXT J
NEXT I
END SUB
 

戻る