0% found this document useful (0 votes)
6 views2 pages

3D Animation of Analytical Solutions

The document is a Python script that simulates and visualizes a mathematical model using 3D graphics. It generates a series of frames representing the solution to a wave equation and saves them as images, which are then compiled into an animation. The script utilizes libraries such as NumPy, Matplotlib, and ImageIO for computations and visualizations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

3D Animation of Analytical Solutions

The document is a Python script that simulates and visualizes a mathematical model using 3D graphics. It generates a series of frames representing the solution to a wave equation and saves them as images, which are then compiled into an animation. The script utilizes libraries such as NumPy, Matplotlib, and ImageIO for computations and visualizations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import numpy as np # математические формулы

import [Link] as plt # для создания 3D графиков


from collections import OrderedDict # для выбора цвета
import imageio # для создания анимации
import os # для создания анимации
from mpl_toolkits.mplot3d import axes3d
cmaps = OrderedDict()

Nx = 50 # количество шагов по х


Ny = 50 # количество шагов по у
M = 200 # количество шагов по t
Xm = 7 # максимальный x
Ym = 5 # максимальный y
T = 0.025

x = [Link](0, Xm, Nx) # все переменные


y = [Link](0, Ym, Ny)
t1 = [Link](0, T, M*2)
ua = [Link]((Nx, Ny, M*2))

# beginning of the program

for i1 in range(0, Nx, 1):


for i2 in range(0, Ny, 1):
for it in range(0, 2*M, 2):
ua[i1, i2, it] = [Link](3*[Link]*x[i1]/14)*[Link](2 * [Link] * y[i2])
ua[i1, i2, it] = ua[i1, i2, it] * [Link](-((3 * 3.1415926535/14)**2 +
(2 * 3.1415926535)**2) *4* t[it])

# painting

x, y = [Link](x, y)

for i in range(0, 2*M, 2):


fig = [Link]()
ax = [Link](projection='3d')
ax.set_xlabel("$x$", fontsize=20)
ax.set_ylabel("$y$", fontsize=20)
ax.set_zlabel("$u$", fontsize=20)
ax.set_zlim(-1.01, 1.01)
ti = round(i * T / M, 3)
ax.set_title("2-ая задача Аналитическое решение \
nПреснов Никита Денисович 306 гр\nВремя"+str(ti))
ax.plot_surface(x, y, ua[:, :, i])
[Link](ax.plot_surface(x, y, ua[:, :, i], cmap=plt.get_cmap('ocean')),
shrink=1, aspect=8)
ax.view_init(30, 60)

if i < 10: # Для верной сортировки по имени


filename = 'frames_anal/astep00' + str(i) + '.png'
else:
if i < 100:
filename = 'frames_anal/astep0' + str(i) + '.png'
else:
filename = 'frames_anal/astep' + str(i) + '.png'
# if i == 150:
# [Link]()
[Link](filename, dpi=96)

[Link]()
print(i)

# анимашка
folder = 'frames_anal'
files = [f"{folder}/{file}" for file in sorted([Link](folder))]

images = [[Link](file) for file in files]


[Link]('Ani/[Link]', images, fps=20)

You might also like