Python Forum
Conjugate Gradient having issues with defining A (function to solve [A]{x} = {b} )
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conjugate Gradient having issues with defining A (function to solve [A]{x} = {b} )
#3
# Who solve sparse matrix with A sparce: A.x = f

# 2x + 3y + 0 = 6
# 0 + 0 + 2z = 4
# 4x + 0 + 1z = 2


#This is an example of sparse matrix above

# So I'm going to name rows, columns and data

import numpy as np
from scipy.sparse import bsr_matrix

row_bsr = np.array([0, 0, 1, 2, 2])
col_bsr = np.array([0, 1, 2, 0, 2])
data_bsr = np.array([2, 3, 2, 4, 1])

A = bsr_matrix((data_bsr, (row_bsr, col_bsr)), shape = (3,3) )
print(A)

# how to declare "b" in this case
# if I print A result OK
print(A)

# but I need x = A⁻1 f
# how do i proceed to extract the x

#=> This is my question because the scipy documentation doesn't show how to solve this.

# have many way:
# 1. bsr_matrix: Block Sparse Row matrix
# 2. coo_matrix: COOrdinate format matrix
# 4. csc_matrix: Compressed Sparce Column matrix
# 5. dia_matrix: Sparce matrix with DAgoal storage
# 6. dok_matrix: Dictionary Of Key based sparce matrix
# 7. lil_matrixÇ Row-based linked list sparse matrix.
# How to solve this matrix to extract the x.
# Common array resolution I can solve in Python but sparse
# arrays can't find the proper codes. The example above is
#pretty simple but my problem is 29x29 with a lot of zeros
#in A and only two values in f.
Reply


Messages In This Thread
RE: Conjugate Gradient having issues with defining A (function to solve [A]{x} = {b} ) - by 1968Edwards - Sep-18-2021, 09:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how can I solve fsolve function error? troddydeeneeeeeey 3 2,451 Oct-14-2021, 07:07 PM
Last Post: deanhystad
  Defining a function with input abcd 5 3,132 Feb-21-2021, 02:34 AM
Last Post: NullAdmin
  subprogram issues: cannot unpack non-iterable function object error djwilson0495 13 6,018 Aug-20-2020, 05:53 PM
Last Post: deanhystad
  Issues with storing variables outside of a function cerulean747 7 3,739 Apr-30-2020, 08:46 AM
Last Post: DeaD_EyE
  When Defining a Function with an Equation as a Default Argument, which Value Is Used? OJGeorge4 4 2,694 Apr-09-2020, 08:48 AM
Last Post: DeaD_EyE
  Gradient background swisha 0 2,369 Mar-04-2020, 03:07 AM
Last Post: swisha
  How to solve a function and get x, y and z? TheZenMan 2 2,292 Mar-22-2019, 01:10 PM
Last Post: scidam
  Problem with defining a function snow_y 4 3,217 Nov-26-2018, 02:13 AM
Last Post: snippsat
  main function scope issues wak_stephanie 1 2,472 Aug-29-2018, 02:53 AM
Last Post: Larz60+
  IDLE indenting 29 columns after defining function Cosmo_Kane 1 2,435 Jun-03-2018, 08:53 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020