Using a sparse matrix for ill-conditioned matrix

9 visualizaciones (últimos 30 días)
Omar Khalifa
Omar Khalifa el 9 de Mzo. de 2021
Respondida: Nipun el 14 de Mayo de 2024
I am using Newton method to solve a system of equations (n = 28) with 28 variables. After calculating the Jacobian, I need to get the inverse of the Jacobian and multiply that by the values of the equations at the given point. Yet, the Jacobian matrix had a condition number of the order 1e27. I scaled my variables and brought the cond(Jacobian) down to the order 1e10. One suggestion was to use a sparse matrix to cure the illness of the matrix. How can I proceed? The sparse matrix of the jacobian is:
1.0e+03 *
(1,1) 0.0000
(10,1) -0.0010
(17,1) -0.0000
(18,1) 0.0000
(19,1) 0.0000
(20,1) 0.0000
(21,1) -0.0000
(22,1) -0.0000
(2,2) 0.0000
(10,2) -0.0010
(16,2) 0.0062
(17,2) 0.0000
(18,2) -0.0004
(19,2) 0.0004
(20,2) 0.0000
(21,2) 0.0000
(22,2) -0.0000
(3,3) 0.0000
(10,3) -0.0010
(17,3) 0.0000
(18,3) 0.0015
(19,3) -0.0132
(20,3) -0.0000
(21,3) 0.0001
(22,3) 0.0004
(4,4) 0.0000
(10,4) -0.0010
(17,4) 0.0000
(18,4) 0.0000
(19,4) -0.0000
(20,4) -0.0003
(21,4) 0.0000
(22,4) 0.0000
(1,5) 0.0001
(9,5) -0.0010
(23,5) -0.0550
(24,5) -0.0012
(25,5) -0.0013
(26,5) -0.0004
(27,5) -2.3518
(28,5) -0.0008
(2,6) 0.0001
(9,6) -0.0010
(23,6) -0.0020
(24,6) -0.0093
(25,6) -0.0005
(26,6) -0.0011
(27,6) -5.6662
(28,6) -0.0008
(3,7) 0.0001
(9,7) -0.0010
(23,7) -0.0025
(24,7) -0.0005
(25,7) -0.0061
(26,7) -0.0014
(27,7) -8.0701
(28,7) -0.0012
(4,8) 0.0001
(9,8) -0.0010
(23,8) 0.0004
(24,8) 0.0006
(25,8) 0.0007
(26,8) 0.0002
(27,8) 1.1535
(28,8) 0.0002
(5,9) -0.0010
(17,9) 0.0010
(6,10) -0.0010
(18,10) 0.0010
(7,11) -0.0010
(19,11) 0.0010
(8,12) -0.0010
(20,12) 0.0010
(5,13) 0.0010
(23,13) 0.0010
(6,14) 0.0010
(24,14) 0.0010
(7,15) 0.0010
(25,15) 0.0010
(8,16) 0.0010
(26,16) 0.0010
(14,17) 0.0010
(13,18) 0.0010
(13,19) -0.0010
(14,19) -0.0010
(17,19) 0.0000
(18,19) 0.0000
(19,19) -0.0000
(20,19) 0.0000
(21,19) -0.0000
(22,19) -0.0000
(23,19) -0.0000
(24,19) -0.0000
(25,19) -0.0000
(26,19) -0.0000
(27,19) -0.0021
(28,19) -0.0000
(1,20) 0.0009
(2,20) 0.0000
(3,20) 0.0000
(4,20) 0.0001
(15,20) 0.0000
(16,20) 0.0076
(1,21) 0.0000
(2,21) 0.0000
(3,21) 0.0001
(4,21) 0.0009
(15,21) -0.0004
(17,22) -0.0000
(18,22) -0.0000
(19,22) -0.0000
(20,22) -0.0000
(21,22) -0.0000
(22,22) 0.0000
(23,23) -0.0000
(24,23) -0.0000
(25,23) -0.0000
(26,23) -0.0000
(27,23) -0.0001
(28,23) -0.0000
(11,24) 0.0010
(21,24) 0.0010
(12,25) 0.0010
(27,25) 0.0010
(15,26) 0.0000
(22,26) 0.0010
(15,27) 0.0001
(28,27) 0.0010
(16,28) 0.0010
while the f(x) matrix which is multiplied by the inverse of the Jacobian is as follow:
-0.0020
-0.0013
-0.0033
-0.0050
0.0096
-0.0361
0.0656
-0.0004
0.0001
-0.0000
0.0000
0.0000
0
0
0.0022
0.0230
-0.0096
0.0361
-0.0656
0.0004
-0.1136
-0.0000
0.0097
-0.0357
0.0658
-0.0003
0.3358
0.0001

Respuestas (1)

Nipun
Nipun el 14 de Mayo de 2024
Hi Omar,
I understand that you want to address the issue of a high condition number in your Jacobian matrix by using a sparse matrix representation to improve the numerical stability and efficiency of solving a system of equations with the Newton method. Given the sparsity and the high condition number of your Jacobian, here are steps to proceed:
Step 1: Use Sparse Matrix Representation
You're already representing your Jacobian as a sparse matrix, which is excellent for both memory efficiency and computational speed, especially for large systems of equations. MATLAB's sparse matrix capabilities are well-suited for this.
Step 2: Avoid Direct Inversion
Given the high condition number, directly inverting the Jacobian can lead to significant numerical errors. Instead of calculating the inverse explicitly, you should solve the system of linear equations (J \Delta x = -f(x)) using MATLAB's backslash operator or an appropriate solver for sparse systems. This approach is more stable and efficient.
Step 3: Implementing the Solution
Assuming J is your sparse Jacobian matrix and f_x is your (f(x)) vector, you can solve for (\Delta x) without explicitly computing the inverse of J:
% Assuming J is already defined as a sparse matrix and f_x is defined
Delta_x = -J \ f_x; % Solve the linear system
Step 4: Update Your Variables
With (\Delta x) computed, update your variables accordingly and proceed with the next iteration of the Newton method:
x_new = x_old + Delta_x; % Update the variables for the next iteration
Step 5: Check for Convergence
After updating, check if your solution has converged to a satisfactory level of accuracy. This can be done by examining the norm of the residual (f(x)) or the change in (x) between iterations. If not converged, repeat Steps 2 to 5 using the new values.
Step 6: Addressing the High Condition Number
Even with these steps, a high condition number can still indicate potential numerical instability. Here are additional strategies to consider:
  • Preconditioning: Apply a preconditioner to improve the condition number of the Jacobian before solving the system.
  • Variable Scaling: You've already scaled your variables, which is good. Ensure the scaling is effective by checking if further adjustments can be made.
  • Regularization: In some cases, adding a small value to the diagonal elements of the Jacobian (a technique known as Tikhonov regularization) can improve numerical stability.
Step 7: Explore Iterative Solvers
For very large systems or systems with extremely high condition numbers, consider using iterative solvers designed for sparse matrices, such as gmres or bicgstab, which can be more robust to issues with the condition number.
% Example using gmres
[Delta_x, flag] = gmres(J, -f_x, [], [], [], [], [], Delta_x);
This approach requires careful tuning of the solver parameters and a good preconditioner to be effective but can offer a path forward for difficult problems.
Hope this helps.
Regards,
Nipun

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by