Using MATLAB to implement Cramer's Rule


by .....
Tags: cramer, implement, matlab, rule
.....
..... is offline
#1
May29-05, 01:54 PM
P: 55
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?
Phys.Org News Partner Science news on Phys.org
SensaBubble: It's a bubble, but not as we know it (w/ video)
The hemihelix: Scientists discover a new shape using rubber bands (w/ video)
Microbes provide insights into evolution of human language
xxacefirexx
xxacefirexx is offline
#2
Oct7-09, 06:32 PM
P: 6
I am curious about how to do this also...

some ideas would be really helpful.
ApexOfDE
ApexOfDE is offline
#3
Oct7-09, 09:53 PM
ApexOfDE's Avatar
P: 122
you just need for loop and det function to solve :|

trambolin
trambolin is offline
#4
Oct8-09, 06:10 AM
P: 341

Using MATLAB to implement Cramer's Rule


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.

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


Register to reply

Related Discussions
Cramer's Rule General Math 2
Cramer's Rule Differential Equations 1
Help with Cramer's rule Calculus & Beyond Homework 3
limitations of cramer's rule Precalculus Mathematics Homework 5
Cramer's rule Introductory Physics Homework 3