COS倍角公式

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

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

OPTION BASE 0
OPTION ARITHMETIC RATIONAL
PUBLIC NUMERIC MAXLEVEL
LET MAXLEVEL=50
DIM NEWCOSINE(MAXLEVEL+1),COSINE(MAXLEVEL),OLDCOSINE(MAXLEVEL)
OPEN #1:NAME "COS倍角公式.html"
ERASE #1
PRINT #1:"<!DOCTYPE html>"
PRINT #1:"<html>"
PRINT #1:"<head>"
PRINT #1:"    <title>COS倍角公式</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>COS倍角公式</h1>"
LET OLDCOSINE(0)=1
LET COSINE(1)=1
FOR K=2 TO MAXLEVEL
   FOR J=0 TO K
      LET NEWCOSINE(J+1)=NEWCOSINE(J+1)+2*COSINE(J)
      LET NEWCOSINE(J)=NEWCOSINE(J)-OLDCOSINE(J)
   NEXT J
   PRINT #1:"<math>"
   PRINT #1:"<mi>cos</mi>"
   PRINT #1:"<mn>";STR$(K);"</mn>"
   PRINT #1:"<mi>θ</mi>"
   PRINT #1:"<mo>=</mo>"
   CALL DISPLAYCOS(K,NEWCOSINE,#1)
   PRINT
   FOR I=0 TO K
      LET OLDCOSINE(I)=COSINE(I)
      LET COSINE(I)=NEWCOSINE(I)
      LET NEWCOSINE(I)=0
   NEXT I
   PRINT #1:"</math>"
   PRINT #1:CHR$(60);CHR$(98);CHR$(114);CHR$(62)
NEXT K
PRINT #1:"</body>"
PRINT #1:"</html>"
CLOSE #1
END

EXTERNAL SUB DISPLAYCOS(K,COSINE(),#1)
OPTION ARITHMETIC RATIONAL
PRINT #1:"<mn>";STR$(COSINE(K));"</mn>"
PRINT #1:"<msup>"
PRINT #1:"    <mi>cos</mi>"
PRINT #1:"    <mn>";STR$(K);"</mn>"
PRINT #1:"</msup>"
PRINT #1:"<mi>θ</mi>"
FOR I=K-1 TO 1 STEP-1
   IF COSINE(I)<>0 THEN
      IF COSINE(I)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
      IF I>1 THEN
         PRINT #1:"<mn>";STR$(ABS(COSINE(I)));"</mn>"
         PRINT #1:"<msup>"
         PRINT #1:"    <mi>cos</mi>"
         PRINT #1:"    <mn>";STR$(I);"</mn>"
         PRINT #1:"</msup>"
         PRINT #1:"    <mi>θ</mi>"
      ELSE
         PRINT #1:"<mn>";STR$(ABS(COSINE(I)));"</mn>"
         PRINT #1:"<mi>cos</mi>"
         PRINT #1:"<mi>θ</mi>"
      END IF
   END IF
NEXT I
IF COSINE(0)<>0 THEN
   IF COSINE(0)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
   PRINT #1:"<mn>";STR$(ABS(COSINE(0)));"</mn>"
END IF
PRINT
END SUB
 

戻る