| 1 |
% !TeX root = ../main.tex |
| 2 |
|
| 3 |
\chapter{程序代码} |
| 4 |
|
| 5 |
本附录给出研究中使用的主要程序代码。 |
| 6 |
|
| 7 |
\section{Python示例代码} |
| 8 |
|
| 9 |
以下是一个简单的Python程序示例: |
| 10 |
|
| 11 |
\begin{verbatim} |
| 12 |
import numpy as np |
| 13 |
import matplotlib.pyplot as plt |
| 14 |
|
| 15 |
def calculate_result(x): |
| 16 |
"""计算函数值""" |
| 17 |
return x**2 + 2*x + 1 |
| 18 |
|
| 19 |
# 生成数据 |
| 20 |
x = np.linspace(-10, 10, 100) |
| 21 |
y = calculate_result(x) |
| 22 |
|
| 23 |
# 绘制图形 |
| 24 |
plt.plot(x, y) |
| 25 |
plt.xlabel('x') |
| 26 |
plt.ylabel('y') |
| 27 |
plt.title('Function Plot') |
| 28 |
plt.grid(True) |
| 29 |
plt.show() |
| 30 |
\end{verbatim} |
| 31 |
|
| 32 |
\section{算法伪代码} |
| 33 |
|
| 34 |
以下是一个算法的伪代码描述: |
| 35 |
|
| 36 |
\begin{verbatim} |
| 37 |
Algorithm: QuickSort(A, low, high) |
| 38 |
Input: Array A, indices low and high |
| 39 |
Output: Sorted array A |
| 40 |
|
| 41 |
1: if low < high then |
| 42 |
2: pivot <- Partition(A, low, high) |
| 43 |
3: QuickSort(A, low, pivot-1) |
| 44 |
4: QuickSort(A, pivot+1, high) |
| 45 |
5: end if |
| 46 |
\end{verbatim} |