Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MATLAB Code for solving linear system with gaussian style

Status
Not open for further replies.

azerturk

Newbie level 6
Joined
Nov 11, 2006
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Azerbaijan-Tebriz
Activity points
1,359
It's my first post here & I don't know much about the rules.plz help me
I need a MATLAB Code(program in the form of .m.file) for solving linear system(equations in the form of matrix) with gaussian style
I only have time for about 2 days :cry:
best regards
 

if you need to solve equation like "R*x=b" you may
used matlab function "inv" such as "x = inv(R) * b", where R is a square matrix, x and b are both vectors.
 

Re: MATLAB Code for solving linear system with gaussian styl

carpa said:
if you need to solve equation like "R*x=b" you may
used matlab function "inv" such as "x = inv(R) * b", where R is a square matrix, x and b are both vectors.
Thanks but it's not 1 equation & this system has n equations with n variables
so the program shoud ask for 'n' and use n×n matrix & we could only use gauss style
 

First which kind of matrix you have (which form they have?)?
Second carpa is right 'caus your system must be written in a matricial form then you'll have R*x=b with R a nxn matrix, x and b are vectors containing each one n eleents.
But if n is very large the inv will take a long time to be executed. So you can use another method just give us the exact problem we can probably help you!
There is a c code for such inversion of matrix I did already upload it at



good luck
 

thanks but the problem is not solving the system
we shoud show the use of gause style in solvig the equations
in the other words we shoud write the algorithm with the help of gause style
 

Re: MATLAB Code for solving linear system with gaussian styl

Ok so here is the algorithm I write it by myself I hope it can help you.
 

    azerturk

    Points: 2
    Helpful Answer Positive Rating
thanks alot that's the point but how could we write it in MATLAM (as a m.file) or in C++
 

Re: MATLAB Code for solving linear system with gaussian styl

Ok again Thes is just made by myself it means that you probably have to verify by yourself.

% The matrix must become on a triangle forme
for (i=0 :n)
r(i,n+1)=y(i) ;
end ;

for (k=1:n-1)
for (i=k+1:n+1)
if (i==k+1)
for (j=k+1:n+1)
r(i,j)=r(I,j)/r(I,i);
end
else
r(i,j)=r(i,j)-r(i,k+1)*r(k+1,j);
end;
end;
end;
% Definition of the second term of problem
for i=1:n,
z(i)=r(i,n+1);
end;
%Solution
for j=1:n
x(j)=z(j);
for k=j+1:n
x(j)=x(j)-r(j,k)*x(k)
end;
end;
 

    azerturk

    Points: 2
    Helpful Answer Positive Rating
great .If it's possible plz post me the file that I could run by MATLAB (m file) because I'm not that much familiar with this program
 

It's not possible because of the extension.
You must first define in the m file you matrix R, the vector y. then you copy the code you past I just did it under Matlab so it must not contains a lot of errors. Just try and we are always here
 

In fact the gauss method is called pivoting one. Because it's about taking the first element of everyline as a pivot and devide the other elements by it. it's a simple principle you just try to make every element under the diagoal null. and when you rewrite your problem the last element of the new y is equal to last element of x. It's more clear in the first doc file
 

I made the m file with the lines below with some edition but it is not giving the right answer

% Method of Gauss for solving linear system: rx=y
n=input('enter the number n for matrix n*n >')
r=input('enter the matrix n*n for r >')
y=input('enter the matrix n*1 for y >')
% The matrix must become on a triangle form
for(i=1:n)
r(i,n+1)=y(i);
end

for(k=0:n-1)
for(i=k+1:n)
if(i==k+1)
for(j=k+1:n+1)
r(i,j)=r(k+1,j)/r(k+1,k+1);
end
else
for(j=k+1:n+1)
r(i,j)=r(i,j)-r(i,k+1)*r(k+1,j);
end
end;
end;
end;
% Definition of the second term of problem
for(i=1:n),
z(i)=r(i,n+1);
end;
%Solution
for(j=n:-1:1)
x(j)=z(j);
for (k=n:-1:j+1)
x(j)=z(j)-r(j,k)*x(k);
end;
end;
x'

I tried with :
r =
1.0000 0.5000 0.3333
0.5000 0.3333 0.2500
0.3333 0.2500 0.2000
y =
1
0
0
but the answer is not
x =
9
-36
30

Added after 2 hours 45 minutes:

plz help
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top