Advertisement
Miquel_Fuster

Graficado de funciones

Dec 19th, 2021
3,573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
COBOL 1.50 KB | None | 0 0
  1. IDENTIFICATION DIVISION.
  2. PROGRAM-ID. GRAFICADO-DE-FUNCIONES.
  3.  
  4. DATA DIVISION.
  5. WORKING-STORAGE SECTION.
  6. 01 COORDENADAS.
  7.     05 X                PIC 99 COMP-3.
  8.     05 Y                PIC 99 COMP-3.
  9.  
  10. 01 MAP-VARIABLES.
  11.     05 MAP-IN-VAL       COMP-2.
  12.     05 MAP-IN-MIN       COMP-2.
  13.     05 MAP-IN-MAX       COMP-2.
  14.     05 MAP-OUT-VAL      COMP-2.
  15.     05 MAP-OUT-MIN      COMP-2.
  16.     05 MAP-OUT-MAX      COMP-2.
  17.  
  18. PROCEDURE DIVISION.
  19.     PERFORM VARYING X FROM 1 BY 1 UNTIL X EQUALS 80
  20.         MOVE X      TO MAP-IN-VAL
  21.     *> Transportar los valores para x de [1, 80] a [0, 2*PI]
  22.         MOVE 1      TO MAP-IN-MIN
  23.         MOVE 80     TO MAP-IN-MAX
  24.         MOVE 0      TO MAP-OUT-MIN
  25.         COMPUTE MAP-OUT-MAX = 2 * FUNCTION PI
  26.         PERFORM MAP
  27.     *> Aplicación de la función seno
  28.         COMPUTE MAP-IN-VAL = FUNCTION SIN(MAP-OUT-VAL)
  29.     *> Transporta los valores para y de [-1, 1] a [21, 1]
  30.         MOVE -1     TO MAP-IN-MIN
  31.         MOVE 1      TO MAP-IN-MAX
  32.         MOVE 21     TO MAP-OUT-MIN
  33.         MOVE 1      TO MAP-OUT-MAX
  34.         PERFORM MAP
  35.     *> Grafica la función
  36.         MOVE MAP-OUT-VAL TO Y
  37.         DISPLAY 'X' COLUMN X LINE Y
  38.     END-PERFORM.
  39.     DISPLAY ' ' COLUMN 1 LINE 23.
  40. STOP RUN.
  41.    
  42. MAP.
  43.     *> Transporta el valor del argumento desde unos rangos a otros dados. Sacada de la función map de Arduino
  44.     COMPUTE MAP-OUT-VAL = (MAP-IN-VAL - MAP-IN-MIN) * (MAP-OUT-MAX - MAP-OUT-MIN) / (MAP-IN-MAX - MAP-IN-MIN) + MAP-OUT-MIN.
  45.    
  46. END PROGRAM GRAFICADO-DE-FUNCIONES.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement