I wrote a code to solve a system of linear equation (a circuit consists of 4-meshes) using Gauss-Jordan elimination method,, but the problem is that the code doesn't display the x-column
this is my code
%Reading the values of resistors, voltages,
R=input(' Enter the values of resistors in k ohm , [ R1 R2 R3 R4 R5 R6 R7 R8 R9 ] = ');
V=input(' Enter the values of voltages in volt , [ V1 V2 ] = ');
%Describe the resistor matrix R
R= [ R(8)+R(5)+R(3) , -R(5) , 0 , -R(3) ;
-R(5) , R(7)+R(1)+R(4)+R(5) , -R(4) , 0 ;
0 , -R(4) , R(2)+R(6)+R(4) , -R(6) ;
-R(3) , 0 , -R(6) , R(6)+R(9)+R(3) ];
%Describe the voltage matrix V
V= [ V(1) ;
0 ;
0 ;
V(2) ];
%mesh currents in mA using Gause-Jordan Elimination method
C=[R,V]; %augmanted matrix
for j=1:4
for z=2:4 %pivoting
if R(j,j)==0
t=R(1,:);R(1,:)=R(z,:);
R(z,:)=t;
end
end
for i=j+1:4 %Convert the elements below the major diagonal to zeros
R(i,:)= R(i,:)-R(j,:)*( R(i,j)/R(j,j) );
end
end
for j=4:-1:2 %Convert the elements above the major diagonal to zeros
for i=j-1:-1:1
R(i,:)= R(i,:)-R(j,:)*( R(i,j)/R(j,j) );
end
end
for s=1:4 %Convert the elements on the major diagonal to ones
R(s,:)= R(s,:)/R(s,s);
x(s)= R(s,4);
end
disp (' Gause-Jordan Elemination method: ');
R
x'

 Réponse acceptée

dpb
dpb le 5 Juil 2014

1 vote

...the code doesn't display the x-column
Bad syntax in
disp (' Gause-Jordan Elemination method: '); R x'
Matlab can't tell R the variable from a supposed function of the same name here. Try sotoo...
disp (' Gause-Jordan Elemination method: '); disp([R x'])
BTW, you might look at
doc \
unless the use of G-J on your own is part of the assignment. Even if so, probably worth checking the comparative results.

4 commentaires

Fatima Al Marzoqi
Fatima Al Marzoqi le 5 Juil 2014
I try what you mention , but still the last column is same as the forth column. No, Not only the Gause-Jordan
dpb
dpb le 6 Juil 2014
Not enough info...how about some data for comparison?
Fatima Al Marzoqi
Fatima Al Marzoqi le 6 Juil 2014
It works finally ! Thank you
Image Analyst
Image Analyst le 10 Juil 2014
So mark it as "Accepted" then so dpb can get credit for it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by