这是一个矩阵运算的库,能够实现一些简单的矩阵预算的功能
创建一个矩阵
create a new matrix
let m1 = new;
println!;
获取值以及设置值
get value & set value
let m1 = new.unwrap;
let value = m1.get;
if let Some = value
m1.set;
let value = m1.get;
if let Some = value
矩阵加减乘的运算
Matrix addition, subtraction, and multiplication operations
// 加法运算 add
let m1 = new.unwrap;
let m2 = new.unwrap;
let m3 = m1 + m2;
println!;
//减法运算 sub
let m1 = new.unwrap;
let m2 = new.unwrap;
let m3 = m2 - m1;
println!;
//乘法运算 multiple
let m1 = new.unwrap;
let m2 = new.unwrap;
let m3 = m2 * m1;
println!;
矩阵乘法
Matrix product
let m1 = new.unwrap;
let m2 = new.unwrap;
let result = m1.product.unwrap;
println!;
矩阵的数乘
Scalar multiplication of a matrix
let m1 = new.unwrap;
let m2 = m1.scale;
println!;
矩阵的转置
Matrix transpose
let m1 = new.unwrap;
let m2 = !m1;
println!;
矩阵的行列式
matrix determinant
let m1 = new.unwrap;
let m2 = !m1;
println!;
物理单位及运算库
解决一部分物理量运算时的单位换算、物理量转换和量纲对齐的问题。
可以让代码向物理公式对齐,而不需要关心具体的单位转换细节。
Resolves unit conversion, physical quantity transformation, and dimensional alignment in physical calculations.
Allows code to align with physical formulas without worrying about unit conversion details.
单位对齐
以长度单位为例,可以通过from_m() 方法生成一个以米为单位的物理量,然后使用as_km() 方法将其转换为以千米为单位的物理量。
也可以用 as_light_year() 方法将其转换为光年的倍数。
Initialize with from_m(), from_km(), etc.
Convert flexibly via as_[unit]() methods.
目前支持的物理量模块: supported physical quantities:
物理量 | 模块名 |
---|---|
长度 | distance |
速度 | velocity |
加速度 | acceleration |
角度 | angular |
角速度 | angular_velocity |
系数 | coef |
角加速度 | angular_acceleration |
面积 | area |
以后会慢慢维护,也欢迎大家提issue和pr。 |
物理量的计算
符合物理计算关系的物理量之间可以进行加减乘除运算,得到符合物理意义的物理量。
例如距离除以时间得到速度,速度除以时间得到加速度。
一旦两个物理量的量纲不匹配,就会编译报错。避免代码写错导致的bug。
Physical quantities with compatible dimensions can be safely added, subtracted, multiplied, or divided while preserving physical meaning.
Examples:
Distance ÷ Time → Velocity
Velocity ÷ Time → Acceleration
Compile-Time Safety:
Operations with dimensionally incompatible quantities will trigger compile errors, preventing invalid physics logic at the code level.