Building up a Matrix using for LOOP and summation

Hello fellows,
I am trying to make this equation but I couldn't do the summaiton part , i tried to use the double for loop but still not sure how to do the summation part,
I have the matrix " a " already defined 4x4 also initial l and u matrices are defiend l=eye(N),u=zeros(N,N);
any hints?

 Accepted Answer

I believe the below is correct.
I=eye(4);
u=zeros(4);
u(1,1:4)=a(1,1:4);
I(1:4,1)=a(1:4,1);
for i=2:4
for j=1:4
u(i,j)=a(i,j)-sum(I(i,1:i-1).*u(1:i-1,j)');
if i<j
I(j,i)=(I(j,i)-sum(I(j,1:i-1).*u(1:i-1,i)'))/u(i,i);
end
end
end

2 Comments

I think its the correct one also, I'll try it on some values,
thanks a lot, for your suuport,
I've applied the code on some known values, this code is supposed to find the lu matrices of a matrix A, using the above expression
what i've got from the code given by you is the following,
I =
6.0000 0 0 0
4.0000 1.0000 0 0
-2.0000 -0.5333 1.0000 0
3.0000 0.8000 0.0845 1.0000
u =
6.0000 4.0000 2.0000 1.0000
-20.0000 -15.0000 -8.0000 -2.0000
-0.6667 2.0000 4.7333 8.9333
1.0563 1.8310 4.0000 -1.1549
I thing that the code representing the mathematical expression has to produce the following
I =
1.0000 0 0 0
0.6667 -0.5000 0.5000 1.0000
-0.3333 1.0000 0 0
0.5000 0 1.0000 0
u=
6.0000 4.0000 2.0000 1.0000
0 3.3333 5.6667 8.3333
0 0 3.0000 0.5000
0 0 0 5.2500
Thanks again for your suuport.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!