Previous in Forum: Impact Sensor   Next in Forum: 3 phase AC to DC Converter
Close
Close
Close
11 comments
Rate Comments: Nested
Active Contributor

Join Date: Apr 2007
Posts: 24

What MATLAB command?

04/21/2007 1:44 PM

Hi

I need a MATLAB command for solving a system of 10-equations

To clarify what I need exactly, this is an example of a 2-equation system:

2x+y=5

x+3y=4

Thanks

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Power-User
Fans of Old Computers - Vector 1 - New Member

Join Date: Sep 2006
Location: Ybor City, Florida, USA
Posts: 104
Good Answers: 1
#1

Re: What MATLAB command?

04/22/2007 9:19 AM

TRY THESE LINKS.

Web Pages that Perform Statistical Calculations!
Over 600 Links (including 380 Calculating Pages) -- And Growing

http://statpages.org/

BRANSON

__________________
"Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover." Mark Twain
Register to Reply
Active Contributor

Join Date: Apr 2005
Posts: 21
#2

Re: What MATLAB command?

04/22/2007 11:39 AM

You just need to rewrite your system of N equations in matrix form, AX=B where A is the N by N matrix of coefficients, X is the N by 1 column of variables, and B is the N by 1 column of constants. For the example you gave,

2x+y=5
x+3y=4

so N=2 and in matrix form (and using MATLAB syntax),

A = [2, 1; 1, 3]
X = [x; y]
B = [5; 4]

So if AX=B, then X=(A^-1)B where A^-1 is the matrix inverse of A. This is where MATLAB does the hard work for you -- once you give it A and B, just type (A^-1)B to have it multipy B by the inverse of A. The N by 1 matrix it spits out will be the solution to your system of equations, which for the example above looks like:

ans=
2.2
0.6

So the solution to your system is x=2.2, y=0.6. It works exactly the same way with any linear system of equations (no exponents, products of two variables, trig functions, etc. -- you will need a somewhat more advances method for those types of problems), and it's always a good idea to plug the numbers back in to the equations for a quick check at the end.

Does that all make sense? I can give you step-by-step instructions if you need them.

__________________
C
Register to Reply
Anonymous Poster
#3

Re: What MATLAB command?

04/22/2007 1:17 PM

Hello!

If it is for linear equations, you can use cramer's rules, with a couple of "for" cicles.

http://en.wikipedia.org/wiki/Cramer's_rule

Register to Reply
Active Contributor

Join Date: Apr 2005
Posts: 21
#4
In reply to #3

Re: What MATLAB command?

04/22/2007 1:24 PM

Yes, this is a variation on the technique that I described above.

__________________
C
Register to Reply
Anonymous Poster
#5
In reply to #4

Re: What MATLAB command?

04/22/2007 1:40 PM

a easier way you can use Gauss Jordan Method put your matrix and use this comand

you just order you matrix for example: for the next 2 equations system

2x+y=4

x+5y=-2

the matrix will be

2 1 4

1 5 -2

MATLAB Function Reference

rref

Reduced row echelon form

Syntax

R = rref(A)
[R,jb] = rref(A)
[R,jb] = rref(A,tol)

Description

R = rref(A) produces the reduced row echelon form of A using Gauss Jordan elimination with partial pivoting. A default tolerance of (max(size(A))*eps *norm(A,inf)) tests for negligible column elements.

[R,jb] = rref(A) also returns a vector jb such that:

  • r = length(jb) is this algorithm's idea of the rank of A.
  • x(jb) are the pivot variables in a linear system Ax = b.
  • A(:,jb) is a basis for the range of A.
  • R(1:r,jb) is the r-by-r identity matrix.

[R,jb] = rref(A,tol) uses the given tolerance in the rank tests.

Roundoff errors may cause this algorithm to compute a different value for the rank than rank, orth and null.

Examples

Use rref on a rank-deficient magic square:

A = magic(4), R = rref(A) A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 R = 1 0 0 1 0 1 0 3 0 0 1 -3 0 0 0 0

See Also

inv, lu, rank

Register to Reply
Active Contributor

Join Date: Apr 2005
Posts: 21
#6
In reply to #5

Re: What MATLAB command?

04/22/2007 1:47 PM

Yes, this would certainly also work. I think, though, that the technique I described above is the most straightforward and easy to understand for someone who is not familiar with MATLAB or linear algebra,

__________________
C
Register to Reply
Active Contributor

Join Date: Apr 2007
Posts: 16
#7
In reply to #6

Re: What MATLAB command?

04/22/2007 2:10 PM

well it is just order the matrix, load the matrix or write it on matlab

A=[2 1 4;5 1 -2]

rref(A) and etc ...

__________________
*N--
Register to Reply
Power-User
Fans of Old Computers - Vector 1 - New Member

Join Date: Sep 2006
Location: Ybor City, Florida, USA
Posts: 104
Good Answers: 1
#8

Re: What MATLAB command?

04/22/2007 4:10 PM
__________________
"Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover." Mark Twain
Register to Reply
Associate
Spain - Member - New Member

Join Date: Mar 2007
Posts: 29
Good Answers: 1
#9

Re: What MATLAB command?

04/23/2007 2:46 AM

Hello,

If you have the symbolic toolbox you could also try the expression "solve", here is your example "solved".

Good look!

equation1='2*x+y=5'

equation2='x+3*y=4'

[solution]=solve(equation1,equation2)

x=solution.x

y=solution.y

__________________
If you only have a hammer, you tend to see every problem as a nail. Abraham Maslow
Register to Reply
Associate
Spain - Member - New Member

Join Date: Mar 2007
Posts: 29
Good Answers: 1
#10
In reply to #9

Re: What MATLAB command?

04/23/2007 2:51 AM

Oh, I forgot, with solve you can also use non linearities, and for your computational purposes it uses the least square error method.

equation1='2*x^2+y=5'

equation2='x+3*y^2=4'

[solution]=solve(equation1,equation2)

x=double(solution.x)

y=double(solution.y)

__________________
If you only have a hammer, you tend to see every problem as a nail. Abraham Maslow
Register to Reply
Guru
Engineering Fields - Control Engineering - New Member China - Member - New Member

Join Date: Sep 2006
Location: CHINA
Posts: 2945
Good Answers: 14
#11

Re: What MATLAB command?

04/24/2007 7:30 AM

use matrix to solve equation.

read its example. if you have 10 equations, there are 10 raw and 10 colume matrix. then divide. just like write on pa\per

Register to Reply
Register to Reply 11 comments
Copy to Clipboard

Users who posted comments:

Anonymous Poster (2); BRANSON (2); cmac (3); cnpower (1); NILOBA (1); qfteer (2)

Previous in Forum: Impact Sensor   Next in Forum: 3 phase AC to DC Converter

Advertisement