https://github.com/gha3mi/forsolver
ForSolver - linear and nonlinear solvers
https://github.com/gha3mi/forsolver
complex-step-differentiation finite-difference-method fortran fortran-package-manager linear-system-solver newton-method newton-raphson nonlinear-systems quasi-newton-method solver
Last synced: 1 day ago
JSON representation
ForSolver - linear and nonlinear solvers
- Host: GitHub
- URL: https://github.com/gha3mi/forsolver
- Owner: gha3mi
- License: bsd-3-clause
- Created: 2023-06-21T20:26:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-09-11T21:52:29.000Z (5 months ago)
- Last Synced: 2025-09-12T00:26:19.086Z (5 months ago)
- Topics: complex-step-differentiation, finite-difference-method, fortran, fortran-package-manager, linear-system-solver, newton-method, newton-raphson, nonlinear-systems, quasi-newton-method, solver
- Language: Fortran
- Homepage: https://gha3mi.github.io/forsolver/
- Size: 1.68 MB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/gha3mi/forsolver)
[](https://github.com/gha3mi/forsolver/releases)
[](https://gha3mi.github.io/forsolver/)
[](https://github.com/gha3mi/forsolver/actions/workflows/CI-CD.yml)
[](https://github.com/gha3mi/forsolver/blob/main/LICENSE)
**ForSolver**: A Fortran library of linear and nonlinear solvers.
## Usage
### Linear system solver
```fortran
use forsolver, only: solve
x = solve(A,b,method)
```
available methods (optional):
- ```gesv```
- ```gels```
### Nonlinear system solver
```fortran
use forsolver, only: nlsolver
call nls%set_options(&
lin_method,&
nl_method,&
fdm_method,&
fdm_tol,&
cs_tol,&
TolFun,&
maxit,&
nmp,&
verbosity )
call nls%solve(F, dFdx, x0, x_sol)
```
available nl_methods:
- ```newton```
- ```newton-modified```
- ```newton-quasi-fd```
- ```newton-quasi-fd-modified```
- ```newton-quasi-cs```
- ```newton-quasi-cs-modified```
fd: finite difference method
cs: complex step method
## Requirements
- A Fortran Compiler
- LAPACK, BLAS or MKL
- Fortran Package Manager (fpm)
## fpm Dependency
If you want to use `ForSolver` as a dependency in your own fpm project,
you can easily include it by adding the following line to your `fpm.toml` file:
```toml
[dependencies]
forsolver = {git="https://github.com/gha3mi/forsolver.git"}
```
## Examples
### Example 1: Linear System Solver
```fortran
program example1
use kinds
use forsolver
implicit none
real(rk), dimension(:,:), allocatable :: A
real(rk), dimension(:) , allocatable :: x, b
integer :: m,n, i, j
m = 3
n = 2
allocate(A(m,n),b(m),x(n))
A(1,:) = [ 1.0_rk, 5.0_rk]
A(2,:) = [ 3.0_rk, 1.0_rk]
A(3,:) = [-2.0_rk, 4.0_rk]
b = [4.0_rk, -2.0_rk, 3.0_rk]
x = solve(A, b)
end program example1
```
### Example 2: Newton's Method for Root Finding
```fortran
module my_function3
use kinds
implicit none
contains
function F1(x) result(F_val)
real(rk), intent(in) :: x
real(rk) :: F_val
F_val = 5.0_rk * x**3 + 8.0_rk * x - 5.0_rk
end function F1
function dF1dx(x) result(dFdx_val)
real(rk), intent(in) :: x
real(rk) :: dFdx_val
dFdx_val = 15.0_rk * x**2 + 8.0_rk
end function dF1dx
end module my_function3
program example2
use forsolver
use my_function3
implicit none
type(nlsolver) :: nls
real(rk) :: x, expected_x
call nls%set_options(&
nl_method = 'newton',&
maxit = 100,&
TolFun = 1e-4_rk,&
verbosity = 1)
call nls%solve(F=F1, dFdx=dF1dx, x0=10.0_rk, x_sol=x)
end program example2
```
## CI Status
## API Documentation
The most up-to-date API documentation for the master branch is available
[here](https://gha3mi.github.io/forsolver/).
To generate the API documentation for `ForSolver` using
[ford](https://github.com/Fortran-FOSS-Programmers/ford) run the following
command:
```shell
ford README.md
```
## Contributing
Contributions to `ForSolver` are welcome!
If you find any issues or would like to suggest improvements, please open an issue.