范德蒙矩阵之范数求解(Python)
import numpy as np
import time # 导入time模块用于计时
# 记录开始时间
start_time = time.time()
def vandermonde_matrix(x, n):
"""生成范德蒙矩阵,x 是输入向量,n 是矩阵阶数"""
return np.vander(x, n, increasing=True)
# 输入向量,共 5 个元素
x = [2, 3, 4, 5,6]
# 生成 5 阶范德蒙矩阵
V = vandermonde_matrix(x, 5)
print("5阶范德蒙矩阵:")
print(V)
# 新增:计算不同类型的矩阵范数
fro_norm = np.linalg.norm(V) # 默认是Frobenius范数
one_norm = np.linalg.norm(V, ord=1) # 1-范数(列和范数)
two_norm = np.linalg.norm(V, ord=2) # 2-范数(谱范数)
inf_norm = np.linalg.norm(V, ord=np.inf) # 无穷范数(行和范数)
det_V = np.linalg.det(V) # 矩阵的行列式
print(f"矩阵的Frobenius范数: {fro_norm:.6f}")
print(f"矩阵的1-范数: {one_norm:.6f}")
print(f"矩阵的2-范数: {two_norm:.6f}")
print(f"矩阵的无穷范数: {inf_norm:.6f}")
print(f"矩阵的行列式: {det_V:.6f}")
# 记录结束时间
end_time = time.time()
# 计算并打印总运行时间
total_time = end_time - start_time
print(f"程序运行总时间: {total_time:.6f} 秒")
posted on 2025-05-13 14:09 Indian_Mysore 阅读(9) 评论(0) 收藏 举报
浙公网安备 33010602011771号