Using MATLAB to implement Cramer's Rule

  • Context: MATLAB 
  • Thread starter Thread starter .....
  • Start date Start date
  • Tags Tags
    Cramer's rule Matlab
Click For Summary

Discussion Overview

The discussion focuses on implementing Cramer's Rule in MATLAB to compute a solution matrix from a given square coefficient matrix and a right-hand side vector. Participants explore how to generalize the implementation for any size matrix, including the use of loops and specific functions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks guidance on writing an m-file that can handle any square coefficient matrix and its corresponding right-hand side vector using Cramer's Rule.
  • Another participant expresses curiosity about the implementation and requests helpful ideas.
  • A third participant suggests that a for loop and the determinant function are necessary to solve the problem.
  • A code snippet is provided by a participant, which includes a function for selecting rows and columns from the matrix, indicating a method to facilitate the implementation of Cramer's Rule.

Areas of Agreement / Disagreement

Participants generally agree on the need for a loop and the determinant function, but specific implementation details and approaches remain varied and unresolved.

Contextual Notes

The discussion does not clarify the assumptions regarding matrix properties or the specific requirements for the input matrices and vectors. The implementation details provided may depend on additional context not fully explored in the discussion.

Who May Find This Useful

Readers interested in MATLAB programming, linear algebra, and numerical methods may find this discussion relevant.

.....
Messages
53
Reaction score
0
Hi all, I'm trying to write an m-file which will compute a solution matrix given a coefficient matrix and right hand side vector using cramer's rule.. which is no problem for a specified size matrix.. but is it possible to write an m-file which computes the solution when ANY square coefficient matrix and it's right hand side vector is entered?

I guess you would need some kind of loop... but I'm not sure how to write the code to have MATLAB substitute the right hand side vector for a different column in the co-efficient matrix for each term...

any suggestions?
 
Physics news on Phys.org
I am curious about how to do this also...

some ideas would be really helpful.
 
you just need for loop and det function to solve :|
 
here is a row/column selector the rest is looping and det function. r and c is the number of row/column that you cancel of the matrix A, Ac is the result that you get.

Code:
function [Ac] = cancelrowcol(A,r,c)
[n,m] = size(A);

% Shortcut to upper left and lower right corner...
if ((r == 1) && (c ==1))
    Ac = sel(A,2:n,2:m);
    return
elseif ((r == n) && (c == m))
    Ac = sel(A,1:n-1,1:m-1);
    return
% Otherwise
else
     Atemp = vertcat(sel(A,1:(r-1),1:m),sel(A,(r+1):n,1:m));
     Ac = horzcat(sel(Atemp,1:(r-1),1:(c-1)),sel(Atemp,1:(r-1),(c+1:m)));
end
end
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
11K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
3K
Replies
1
Views
4K
  • · Replies 41 ·
2
Replies
41
Views
11K
  • · Replies 9 ·
Replies
9
Views
3K