|
|
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 |
|
|
T = 1 |
|
|
r = 0.05 |
|
|
sigma = 0.2 |
|
|
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 |
|
|
|