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.

matrix division in matlab.

Status
Not open for further replies.

ramani

Member level 4
Joined
Dec 21, 2005
Messages
78
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Location
india
Activity points
1,919
hi to all,

i need to solve ax=b.
where a is a n×n tridiagonal matrix. b is n×n matix. and x is n×n matrix.
what command in matlab i have to use to get the value of x.

shall i use b/a;
but if i use like this i am getting a wrong value.
what is the correct syntax.

a=[1,2,0;3,1,2;0,3,1];
>> a

a =

1 2 0
3 1 2
0 3 1
b=[3,3,3;3,3,3;3,3,3];
>> b

b =

3 3 3
3 3 3
3 3 3
b/a

ans =

-0.2727 1.0909 0.8182
-0.2727 1.0909 0.8182
-0.2727 1.0909 0.8182

which is wrong one.

even i use b./a i am getting wrong answer.

can anyone please help me
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,178
Beware the non-commutativity of matrix multiplication and division. You solved xa=b instead of ax=b.

Try a matrix left division:

a = [1,2,0; 3,1,2; 0,3,1];
b = [3,3,3; 3,3,3; 3,3,3];
x = a \ b;
a * x

ans =
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000 3.00000000000000
 

Quibbler

Junior Member level 1
Joined
Dec 6, 2005
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Trinidad and Tobago
Activity points
1,439
If A X = B
then A-1 A X = A-1 B
where A-1 is the inverse of A

so X = A-1 B

So you have to find the inverse of A - never used matlab so don't know how to do it. But here's a basic routine that will invert the NxN matrix E and return the inverted matrix X.

Code:
DEFINT I-N
FOR I = 1 TO N
FOR J = 1 TO N
F(I, J) = E(I, J)
X(I, J) = 0!
NEXT J
X(I, I) = 1!
NEXT I
FOR J = 1 TO N
FOR I = 1 TO N
IF I <> J THEN
F(J, I) = F(J, I) / F(J, J)
X(J, I) = X(J, I) / F(J, J)
END IF
NEXT I
X(J, J) = X(J, J) / F(J, J)
F(I, I) = 1!
FOR K = 1 TO N
IF K <> J THEN
FOR L = 1 TO N
IF L <> J THEN F(K, L) = F(K, L) - F(K, J) * F(J, L)
X(K, L) = X(K, L) - F(K, J) * X(J, L)
NEXT L
F(K, J) = 0!
END IF
NEXT K
NEXT J
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,178
Yes, inverse works fine too.
In MATLAB, the inverse of square matrix A is inv(A).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top