Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setting for solving A x = b with A in R^{2 \times 3}, x in R^{3} and b in R^{2}? #102

Open
Aijunly opened this issue Dec 12, 2024 · 1 comment

Comments

@Aijunly
Copy link

Aijunly commented Dec 12, 2024

It looks like you're asking for help with setting up a linear equation system in the form ( Ax = b ) using Julia, where ( A ) is a ( 2 \times 3 ) matrix, ( x ) is a ( 3 )-dimensional vector, and ( b ) is a ( 2 )-dimensional vector. Your code snippet is almost correct, but there are a couple of minor adjustments needed for clarity and correctness.

Here's a corrected version of your code:

## Packages
using Pardiso
using SparseArrays
gpmt = MKLPardisoSolver() # or gpmt = PardisoSolver()

## Data
A = [1 1 1; 2 4 2.0]  # Define the matrix A
Acsr = sparse(A)
b = [35; 94.0]        # Define the vector b

## Solving...
set_msglvl!(gpmt, 1) 
xsol = solve(gpmt, Acsr , b)

The above gives me that

=== PARDISO is running in In-Core mode, because iparam(60)=0 ===
...
2-element Vector{Float64}:
 23.0
 12.0

But the result has only 2 elements. And i want 3 elements. If i write the code of

## Solving...
xs = zeros(3,1); 
solve!(gpmt, xs, Acsr , b)

It gives me errors of

ERROR: DimensionMismatch: solution has (3, 1), RHS has size as (2,).

Although, i know reason from the dims of A{2,3} * x{3,1} = b{2,1}. And I should write code of

## Packages
using Pardiso
using SparseArrays
gpmt = MKLPardisoSolver() # or gpmt = PardisoSolver()

## Data
A = [1 1 1; 2 4 2.0]  # Define the matrix A
Acsr = sparse(A'*A)
b = [35; 94.0]        # Define the vector b
brhs = reshape(A'*b,3,1)

## Solving...
set_msglvl!(gpmt, 1) 
xs = zeros(3,1); 
solve!(gpmt, xs, Acsr , brhs)

So that, i want ask a question of Ax = b with A in ( R^{m \times n } ), x in R^{n} and b in R^{m} satisfying m < n. Hence, how to setting for solving this type of A x = b? And i translate Ax = b into A'*A x = A'*b, then solving it by Pardiso?

Sincerely,
Aijunly, Jun Wang.

@mipals
Copy link
Member

mipals commented Dec 12, 2024

Pardiso only works for square systems. In your case what is happening is that it is actually solving the square system containing only first m columns.

Maybe we should update this so that it returns an error when trying to solve a non-square system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants