필터 지우기
필터 지우기

How do I store row swap information in a vector?

조회 수: 1 (최근 30일)
Sandeep
Sandeep 2012년 10월 22일
Suppose I have 2 matrices A and B.. A is an NxN matrix and B is an Nx1 matrix. Now, I want to swap certain rows in A and store the information in an array P and use the array P to swap the rows in B. Is there a way to do this?
  댓글 수: 2
Image Analyst
Image Analyst 2012년 10월 22일
I don't know what P is - is it A with "certain rows" swapped? What does "use the array P to swap the rows in B" mean. How, given only that P matrix, are you supposed to know what to do with B? If you know which rows in A were swapped and you wanted to swap the same elements in B, you wouldn't even need P at all. Please give a small example (say N = 4 or 5) showing A, P, and B.
Sandeep
Sandeep 2012년 10월 23일
Ok, let me give an example.. Suppose I want to solve Ax=B using gaussian elimination with partial pivoting in 2 steps. First, I want to apply LU decomposition on A and then solve LUx=B. Now, I want to create 2 functions, one to solve LU decomposition and another one to solve LUx=B. The first function needs to store L and U in a single vector and create a P vector which stores the swap information. The second function takes L and U in a single matrix, P and B as input and then solves for x. My question is how to store the row swap information in P in function 1 and how to implement it in the second function on B.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sachin Ganjare
Sachin Ganjare 2012년 10월 22일
Command for swapping array:
For 3x3 Matrix A:
A([1 3], :) = A([3 1], :)
This will swap row 1 with 3.
Now you can use for loop for swapping the rows, at the same time saving swapped rows information in matrix P.
Then you run another loop for swapping rows in matrix B, but this time with swapping information present in matrix P.
Hope this helps!!!

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by