TAN倍角公式

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

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

OPTION BASE 0
OPTION ARITHMETIC RATIONAL
PUBLIC NUMERIC MAXLEVEL
LET MAXLEVEL=50
DIM A(MAXLEVEL),B(MAXLEVEL),AA(MAXLEVEL),BB(MAXLEVEL),C(1),D(1)
LET C(0)=1
LET D(1)=1
LET B(1)=1
LET A(0)=1
OPEN #1:NAME "TAN倍角公式.html"
ERASE #1
PRINT #1:"<!DOCTYPE html>"
PRINT #1:"<html>"
PRINT #1:"<head>"
PRINT #1:"    <title>TAN倍角公式</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>TAN倍角公式</h1>"
FOR K=2 TO MAXLEVEL
   FOR J=0 TO 1
      FOR I=0 TO MAXLEVEL-J
         LET AA(I+J)=AA(I+J)+A(I)*C(J)-B(I)*D(J)
         LET BB(I+J)=BB(I+J)+B(I)*C(J)+A(I)*D(J)
      NEXT I
   NEXT J
   MAT A=AA
   MAT B=BB
   MAT AA=ZER
   MAT BB=ZER
   PRINT #1:"<math>"
   PRINT #1:"<mi>tan</mi>"
   PRINT #1:"<mn>";STR$(K);"</mn>"
   PRINT #1:"<mi>θ</mi>"
   PRINT #1:"<mo>=</mo>"
   PRINT #1:"<mfrac>"
   PRINT #1:"<mrow>"
   CALL DISPLAY(B,#1)
   PRINT #1:"</mrow>"
   PRINT #1:"<mrow>"
   CALL DISPLAY(A,#1)
   PRINT #1:"</mrow>"
   PRINT #1:"</mfrac>"
   PRINT #1:"</math>"
   PRINT #1:CHR$(60);CHR$(98);CHR$(114);CHR$(62)
   PRINT #1:CHR$(60);CHR$(98);CHR$(114);CHR$(62)
NEXT K
PRINT #1:"</body>"
PRINT #1:"</html>"
CLOSE #1
END

EXTERNAL SUB DISPLAY(B(),#1)
OPTION ARITHMETIC RATIONAL
FOR JJ=MAXLEVEL TO 0 STEP-1
   IF B(JJ)<>0 THEN EXIT FOR
NEXT JJ
IF ABS(B(JJ))<>1 AND JJ>1 THEN
   PRINT #1:"<mn>";STR$(B(JJ));"</mn>"
   PRINT #1:"<msup>"
   PRINT #1:"    <mi>tan</mi>"
   PRINT #1:"    <mn>";STR$(JJ);"</mn>"
   PRINT #1:"</msup>"
   PRINT #1:"    <mi>θ</mi>"
ELSEIF ABS(B(JJ))=1 AND JJ>1 THEN
   IF B(JJ)<0 THEN PRINT #1:"<mo>-</mo>"
   PRINT #1:"<msup>"
   PRINT #1:"    <mi>tan</mi>"
   PRINT #1:"    <mn>";STR$(JJ);"</mn>"
   PRINT #1:"</msup>"
   PRINT #1:"<mi>θ</mi>"
END IF
FOR J=JJ-1 TO 2 STEP-1
   IF B(J)<>0 THEN
      IF B(J)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
      IF B(J)<>1 THEN
         PRINT #1:"<mn>";STR$(ABS(B(J)));"</mn>"
         PRINT #1:"<msup>"
         PRINT #1:"    <mi>tan</mi>"
         PRINT #1:"    <mn>";STR$(J);"</mn>"
         PRINT #1:"</msup>"
         PRINT #1:"<mi>θ</mi>"
      ELSEIF B(J)=1 THEN
         PRINT #1:"<msup>"
         PRINT #1:"    <mi>tan</mi>"
         PRINT #1:"    <mn>";STR$(J);"</mn>"
         PRINT #1:"</msup>"
         PRINT #1:"<mi>θ</mi>"
      END IF
   END IF
NEXT J
IF B(1)<>0 THEN
   IF JJ>1 THEN
      IF B(1)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
   END IF
   IF B(1)<>1 THEN
      PRINT #1:"<mn>";STR$(ABS(B(1)));"</mn>"
      PRINT #1:"<mi>tan</mi>"
      PRINT #1:"<mi>θ</mi>"
   ELSEIF B(1)=1 THEN
      PRINT #1:"<mi>tan</mi>"
      PRINT #1:"<mi>θ</mi>"
   END IF
END IF
IF B(0)<>0 THEN
   IF B(0)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
   PRINT #1:"<mn>";STR$(ABS(B(0)));"</mn>"
END IF
END SUB
 

戻る