I have some trouble on setting of n-linear equations in matlab.I don't know how can I declare in matlab.I need matlab code for setting of n-linear equations..
You can write n-linear equations as one matrix equation to solve it. Here you can find great example: http://blogs.mathworks.com/pick/2007/09/13/matlab-basics-video-solving-linear-equations/ (video!)
See also these pages:
http://en.wikipedia.org/wiki/System_of_linear_equations
http://en.wikipedia.org/wiki/Matrix_equation
You can solve a linear system in various ways, depending on whether there exists a unique solution or not.
A simple way is by reducing it to reduced-echelon form (rref).
Consider the system:
x + 5y = 4
2x - y = 1
You can write the coefficient matrix A, and the RHS, B as follows: ('
is the transpose operator)
>> A = [1 5; 2 -1]
A =
1 5
2 -1
>> B = [4 1]'
B =
4
1
You can write it as an augmented matrix (A|B):
>> horzcat(A,B)
ans =
1 5 4
2 -1 1
And then find the REF(A|B)
>> rref(ans)
ans =
1.0000 0 0.8182
0 1.0000 0.6364
And hence x ~ .8182, y ~ .6364.
The absolutely fastest way to solve linear equations in MATLAB is simply to setup your equation on the form
AX = B
and then solve by
X = A\B
You can issue
help mldivide
to find more information on matrix division and what limitations it has.