Abekta

The Encyclopédie of CASSA

User Tools

Site Tools


courses:ast401:4.3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

courses:ast401:4.3 [2025/07/21 02:12] – created asadcourses:ast401:4.3 [2025/07/21 02:31] (current) – [Python Code Example] asad
Line 65: Line 65:
   - **Step 7**: Repeat inward to the core.   - **Step 7**: Repeat inward to the core.
  
-==== Python Code Example ==== +==== Python ==== 
- +<html><script src="https://gist.github.com/kmbasad/3fb15cca49b0999f6134c0bd34691880.js"></script></html>
-Here's a Python implementation of the method: +
- +
-```python +
-import numpy as np +
-import matplotlib.pyplot as plt +
- +
-# Constants +
-G = 6.67430e-11 +
-R_earth = 6.371e6 +
-rho_surface = 3000 +
-M_earth = 5.972e24 +
-N = 100 +
-dr = R_earth +
- +
-# Seismic speeds +
-vp = 8000  # m/+
-vs = 4500  # m/s +
-K_over_rho = vp**2 - (4/3) * vs**2 +
- +
-# Initialize +
-r = np.linspace(R_earth, 0, N) +
-rho = np.zeros(N) +
-mass = np.zeros(N) +
-rho[0] = rho_surface +
-mass[0] = M_earth +
- +
-# Loop +
-for i in range(1, N): +
-    mass[i] = mass[i-1] - 4*np.pi*r[i-1]**2 * dr * rho[i-1] +
-    delta_rho = - (rho[i-1]**2 * G * mass[i]) (K_over_rho * r[i-1]**2) * dr +
-    rho[i] = rho[i-1] + delta_rho +
- +
-# Plot +
-plt.plot(r 1000, rho) +
-plt.xlabel("Radius (km)"+
-plt.ylabel("Density (kg/m³)"+
-plt.title("Earth's Density Profile (Williams–Adams Algorithm)"+
-plt.gca().invert_xaxis() +
-plt.show() +
courses/ast401/4.3.1753085538.txt.gz · Last modified: by asad

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki