vulkaan.py

Created by numworks-nl

Created on July 08, 2024

893 Bytes

Dit script hoort bij een artikel uit het Pythagoras magazine 62-3. Hier is het artikel en een uitgebreidere beschrijving bij de totstandkoming van dit script: https://pyth.eu/functies-met-je-gr-onderzoeken. Op het moment van schrijven was de module Numpy nog niet beschikbaar op de NumWorks, inmiddels wel. Dus wellicht kan dit nog een stukje mooier gemaakt worden :).


from matplotlib.pyplot import *
import math

Pi = math.pi
Xas = 0
Yas = -7000

RNG = 20
BND = 3.9
RST = 1/2-1/BND
XX = 9000 * 4250
X = math.sqrt(XX)

for ii in range(RNG+1):
    i = RNG-ii
    alpha = (1/(BND*RNG) * (i-4) + RST) * Pi
    ta = math.tan(alpha)
    a = -(1 + ta**2)/9000
    b = ta
    c = 2000
    disc = b*b - 4*a*c
    worteldisc = math.sqrt(disc)
    X0 = (-b+worteldisc)/(2*a)
    X1 = (-b-worteldisc)/(2*a)
    PN = min(8,max(round((X1-X0)/1000),5))
    xm = [-X1 + i*X1/(PN-1.) for i in range(PN)]
    fm = [a*xi**2 - b*xi + c for xi in xm]
    col = [255*i/RNG, 255*(0.5-i/(2*RNG)), 255*(1-i/RNG)]
    plot(xm, fm,col)
    xp = [X1*i/(PN-1) for i in range(PN)]
    fp = [a*xi**2 + b*xi + c for xi in xp]
    plot(xp,fp,col)

PN = round(X/300)
x = [-X + i*2*X/(PN-1) for i in range(PN)]
f = [-xi**2/9000 + 4250 for xi in x]
plot(x,f,[0,255,0])
grid()
show()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.