dimforge / dimforge/nalgebra

Only zero solution when solving a linear system with SVD

Open
#368 2 comments 0 reactions 0 assignees View on GitHub
enhancement P-low
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

I'm solving homogeneous linear equations `Ax=b` where `b` is `0`. But there was only zero solution.
Like following:
```
A:
┌ ┐
│ 1 0 -1 0 0 0 │
│ 0 1 0 0 0 -2 │
│ 0 1 -2 -1 -1 0 │
│ 0 3 -6 -1 -2 -1 │
└ ┘

b:
┌ ┐
│ 0 │
│ 0 │
│ 0 │
│ 0 │
└ ┘
```
And by using the SVD method, it gave me the `x` which is:
```
x:
┌ ┐
│ 0 │
│ 0 │
│ 0 │
│ 0 │
│ 0 │
│ 0 │
└ ┘
```
My code:
```rust
extern crate nalgebra as na;

use na::base::{Dynamic, MatrixMN};
use na::linalg::SVD;

fn main() {
let m = MatrixMN::::from_row_slice(
4,
6,
&[
1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -2.0, 0.0, 1.0, -2.0, -1.0,
-1.0, 0.0, 0.0, 3.0, -6.0, -1.0, -2.0, -1.0,
],
);
println!("A: {}", m);
let b = MatrixMN::::from_row_slice(4, 1, &[0.0, 0.0, 0.0, 0.0]);
println!("b: {}", b);
let s = SVD::new(m, true, true);
let ans = s.solve(&b, 0.0000001);
println!("x: {}", ans);
}
```
How to got other non-zero solutions?
There are two more basic solutions for this system.
which are:
3/4, 2, 3/4, 1/2, 0, 1
and -1/4, 0, -1/4, -1/2, 1, 0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.