1个不稳定版本
0.1.0 | 2023年11月25日 |
---|
#633 in 数学
2.5MB
699 行
包含 (WOFF字体,400KB) NanumBarunGothic-0f09457c7a19b7c6.ttf.woff2,(WOFF字体,135KB) FiraSans-Medium-8f9a781e4970d388.woff2,(WOFF字体,130KB) FiraSans-Regular-018c141bf0843ffd.woff2,(WOFF字体,82KB) SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2,(WOFF字体,77KB) SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,(WOFF字体,45KB) SourceCodePro-It-1cc31594bf4f1f79.ttf.woff2 等更多.
ls_solver
线性系统求解的简单工具和库
简介
本项目旨在提供通过迭代方法求解线性系统的纯Rust实现 rust-lang 的工具。生成的工具 ls_solver
可以接受矩阵A和一个可选向量b作为输入,然后计算系统Ax=b的解向量。
为了更好地满足用户需求,ls_solver
具有双重接口,既可以作为独立的命令行工具使用,也可以在更大的项目中作为库使用。此外,还有几个可选参数,用户可以根据需要轻松配置。以下章节将详细介绍这些功能。
本报告将概述 ls_solver
的实现功能,以及测试中获得的结果,并对它的功能进行简要说明。
本文档中的所有材料,如图表或结果表,以及 ls_solver
本身,都可在 https://github.com/dcmonti/ls_solver 上找到。
Ls_solver
使用 ls_solver
的唯一要求是拥有Rust 2021版(或更高版本)及其包管理器Cargo(可在 此处 下载)。
满足此要求后,只需克隆仓库并使用以下命令进行编译
git clone https://github.com/dcmonti/ls_solver
cd ls_solver
cargo build --release
为了最大限度地提高 ls_solver
的性能,如果可移植性不是问题,您可以使用
RUSTFLAGS="-C target-cpu=native"
可执行文件现在可以在 target/release
中找到。
操作
由于 ls_solver
可以用作库和独立工具,因此将解释这两种使用模式。
命令行使用
要从命令行使用 ls_solver
,只需在项目目录中运行即可
target/release/ls_solver [MATRIX_PATH] <OPT_ARGS>
在这里,[MATRIX_PATH]
是包含矩阵的 .mtx
格式文件的路径。矩阵必须遵循矩阵市场的坐标格式(可在此查看此处)。
<OPT_ARGS>
是用户可以根据需求指定的参数。例如,为了计算解决文件 example.mtx
中矩阵的Jacobi方法的精度,容忍度为 $10^{-6}$,命令将是
target/release/ls_solver /path/to/example.mtx -m 0 -t 6
有关所有选项和可能值的详细说明,请执行
target/release/ls_solver --help
这将显示以下屏幕
Usage: ls_solver [OPTIONS] <MATRIX_PATH> [VECTOR_PATH]
I/O:
-o, --output <OUTPUT_PATH>
Output file with approximate solution,
if None solution will not be printed
[default: None]
<MATRIX_PATH>
Input matrix (in .mtx format)
[VECTOR_PATH]
Input vector (in .mtx format).
If not specified x := [1 1 ... 1] and b := ax
[default: None]
Settings:
-m, --method <METHOD>
0: Jacobi
1: Gauß-Seidel
2: gradient
3: conjugate gradient
4: Jacobi-preconditioned gradient (only if matrix is SPD)
[default: 0]
-t, --tolerance <TOLERANCE>
Set tolerance as desired negative exponent (e.g. 4 is 0.0001)
[default: 4]
-i, --max_iter <MAX_ITER>
Set max number of iterations for the routine
[default: 20000]
-O, --omega <OMEGA>
Set relax factor with float desired
Used only if method is 0 or 1
[default: 1]
-s, --set-mode <SETTING>
Used only if [VECTOR_PATH] is specified
0: consider vector as b and solve the system Ax=b
1: consider vector as x and evaluate method precision
[default: 0]
库使用
ls_solver
可以作为库在其他 Rust 项目中使用,通过在 Cargo.toml
文件中添加以下依赖项
[dependencies]
ls_solver = { git = "https://github.com/dcmonti/ls_solver" }
然后,ls_solver
可以通过在需要库的文件中添加以下行轻松地在项目中使用
use ls_solver::api::*;
这些函数的详细说明可以在文档中找到,文档位于项目文件夹中(doc/ls_solver/api/index.html
)。
致谢
贡献者
戴维德·塞萨雷·蒙特(https://github.com/dcmonti)
萨穆埃尔·坎帕内拉(https://github.com/kmp222)
依赖项
~10MB
~196K SLoC