File size: 2,266 Bytes
351ed7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm


def finance_demo():
    """
    Simulates a Black-Scholes pricing scenario for European call options.

    Returns:
        matplotlib.figure.Figure: A plot of option price vs stock price using the Black-Scholes formula.
    """

    fig, ax = plt.subplots()
    S = np.linspace(1, 100, 100)
    K = 50  # strike price
    T = 1   # time to maturity
    r = 0.05  # risk-free rate
    sigma = 0.2  # volatility
    d1 = (np.log(S / K) + (r + sigma**2 / 2) * T) / (sigma * np.sqrt(T))
    d2 = d1 - sigma * np.sqrt(T)
    call_price = S * norm.cdf(d1) - K * np.exp(-r * T) * norm.cdf(d2)
    ax.plot(S, call_price)
    ax.set_title("Black-Scholes Call Option Price")
    ax.set_xlabel("Stock Price")
    ax.set_ylabel("Option Price")
    return fig


def quantum_demo():
    """
    Simulates a 1D quantum wavefunction as a product of a Gaussian envelope and a cosine wave.

    Returns:
        matplotlib.figure.Figure: A plot representing a wavefunction in space.
    """

    x = np.linspace(-5, 5, 500)
    t = 0.1
    psi = np.exp(-x**2) * np.cos(5 * x - t)
    fig, ax = plt.subplots()
    ax.plot(x, psi)
    ax.set_title("Wavefunction: Particle in a Potential")
    ax.set_xlabel("Position")
    ax.set_ylabel("Amplitude")
    return fig


def fluid_demo():
    """
    Simulates a 1D velocity field representing wave-like fluid behavior.

    Returns:
        matplotlib.figure.Figure: A sine wave representing fluid velocity over space.
    """

    x = np.linspace(0, 2 * np.pi, 100)
    t = 1.0
    u = np.sin(x - t)
    fig, ax = plt.subplots()
    ax.plot(x, u)
    ax.set_title("1D Fluid Velocity Field")
    ax.set_xlabel("x")
    ax.set_ylabel("u(x, t)")
    return fig


def bio_demo():
    """
    Simulates a reaction-diffusion pattern, commonly seen in developmental biology.

    Returns:
        matplotlib.figure.Figure: A morphogen concentration gradient over space.
    """
    
    x = np.linspace(0, 1, 100)
    t = 0.1
    u = np.exp(-10 * (x - 0.5) ** 2) * np.exp(-t)
    fig, ax = plt.subplots()
    ax.plot(x, u)
    ax.set_title("Reaction-Diffusion: Morphogen Gradient")
    ax.set_xlabel("Position")
    ax.set_ylabel("Concentration")
    return fig