Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Project: My Project
Views: 30
Image: ubuntu2204
Kernel: Python 3 (system-wide)

Importing necessary libraries

We'll need numpy for mathematical functions and matplotlib for plotting the 3D graph.

import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D

Defining the wave equation

The wave equation in 3-dimensions can be represented as:

u(x,t)=Asin(kxωt+ϕ)u(x, t) = A \sin(kx - \omega t + \phi)

Where:

  • AA is the amplitude

  • kk is the wave number

  • ω\omega is the angular frequency

  • ϕ\phi is the phase

Define the variables:

A = 1.0 # Amplitude k = 2 * np.pi / 10 # Wave number omega = 2 * np.pi / 5 # Angular frequency phi = 0 # Phase

Generating the grid

Create a grid for xx and tt:

x = np.linspace(0, 10, 100) t = np.linspace(0, 5, 100) x, t = np.meshgrid(x, t)

Defining the wave function

Calculate the wave function u(x,t)u(x, t):

u = A * np.sin(k * x - omega * t + phi)

Plotting the wave equation

Create a 3D plot of the wave equation:

fig = plt.figure(figsize=(10, 7)) ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x, t, u, cmap='viridis') ax.set_title('3D Plot of the Wave Equation') ax.set_xlabel('x') ax.set_ylabel('t') ax.set_zlabel('u(x, t)') plt.show()
Image in a Jupyter notebook
a=2 b=3 b-a
Intro

  • σν=γ\sigma-\nu=\gamma