Question

In: Computer Science

l = [0 1 -2 1 1]; d = [2 -2 4 2 2]; r =...

l = [0 1 -2 1 1];

d = [2 -2 4 2 2];

r = [-1 1 -1 -2 0];

b = [2 0 -6 1 4];

n = length(d);

x= zeros(n,1);

for i = 2:n

factor = l(i)/d(i-1);

d(i) = d(i) - factor*r(i-1);

b(i) = b(i) - factor*b(i-1);

end

x(n) = b(n)/d(n);

for i = n-1:-1:1

x(i) = b(i)-r(i)*x(i+1) / d(i);

end

x1 = x(1);

x2 = x(2);

x3 = x(3);

x4 = x(4);

fprintf('\nx1 = %f\nx2 = %f\nx3 = %f\nx4 = %f\n',x1,x2,x3,x4);

this is matlab code!

It's a question of getting answers using the Thomas method.

The answer should be x1=1, x2=0, x3=-1, x4=2, x5=1.

Please fix what's wrong.

Solutions

Expert Solution

CODE:-

l = [0 1 -2 1 1];

d = [2 -2 4 2 2];

r = [-1 1 -1 -2 0];

b = [2 0 -6 1 4];

n = length(d);

x= zeros(n,1);

for i = 2:n

factor = l(i)/d(i-1);

d(i) = d(i) - factor*r(i-1);

b(i) = b(i) - factor*b(i-1);

end

x(n) = b(n)/d(n);

for i = n-1:-1:1

x(i) = (b(i)-r(i)*x(i+1)) / d(i);

end

x1 = x(1);

x2 = x(2);

x3 = x(3);

x4 = x(4);
x5 = x(5);
fprintf('\nx1 = %d\nx2 = %d\nx3 = %d\nx4 = %d\nx5 = %d\n',x1,x2,x3,x4,x5)

screenshots of code and result:-

please like if you find it needfull.....


Related Solutions

L = {a r b s | r, s ≥ 0 and s = r 2}....
L = {a r b s | r, s ≥ 0 and s = r 2}. Show that L is not regular using the pumping lemma
Let L = {0 r | r = s 2 , s a positive integer}. Give...
Let L = {0 r | r = s 2 , s a positive integer}. Give the simplest proof you can that L is not regular using the pumping lemma.
A= 1 2 4 0 1 -2 -1 0 1 2 0 3 8 1 4...
A= 1 2 4 0 1 -2 -1 0 1 2 0 3 8 1 4 . Let W denote the row space for A. (a) Find an orthonormal basis for W and for W⊥. (b) Compute projW⊥(1 1 1 1 1 ).
If n = 4 l=1 ml=0 ms= -1/2 What is the element , what is the...
If n = 4 l=1 ml=0 ms= -1/2 What is the element , what is the elements complete electron configuration WITHOUT noble gas abbreviation & is it paramagnetic or diamagnetic??
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)MEAN – B.)MEDIAN - C.)MODE - D.)STANDARD DEVIATION – E.)5 NUMBER SUMMARY – F.)BOX AND WHISKERS PLOT – G.) OUTLIERS-
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)5 NUMBER SUMMARY – B.)BOX AND WHISKERS PLOT – C.) OUTLIERS-
A:=<<0,-1,1>|<4,0,-2>|<2,-1,0>|<2,1,1>>; Matrix(3, 4, [[0, 4, 2, 2], [-1, 0, -1, 1], [1, -2, 0, 1]]) (a)...
A:=<<0,-1,1>|<4,0,-2>|<2,-1,0>|<2,1,1>>; Matrix(3, 4, [[0, 4, 2, 2], [-1, 0, -1, 1], [1, -2, 0, 1]]) (a) Use the concept of matrix Rank to argue, without performing ANY calculation, why the columns of this matrix canNOT be linerly independent. (b) Use Gauss-Jordan elimination method (you can use ReducedRowEchelonForm command) to identify a set B of linearly independent column vectors of A that span the column space of A. Express the column vectors of A that are not included in the set...
d^2y/dx^2 − dy/dx − 3/4 y = 0, y(0) = 1, dy/dx(0) = 0, Convert the...
d^2y/dx^2 − dy/dx − 3/4 y = 0, y(0) = 1, dy/dx(0) = 0, Convert the initial value problem into a set of two coupled first-order initial value problems and find the exact solution to the differential equatiion
How many electrons can occupy the system with l=0, l=2 and l=4. What is number of...
How many electrons can occupy the system with l=0, l=2 and l=4. What is number of possible orientations of the orbital angular momentum with l=5? What is the smallest z-component of the orbital angular momentum?
1) The daily demand, D, of sodas in the break room is: D 0 1 2...
1) The daily demand, D, of sodas in the break room is: D 0 1 2 3 P=(D=d) 0.1 0.2 0.4 0.3 i) Find the probability that the demand is at most 2. ii) Compute the average demand of sodas. iii) Compute SD of daily demand of sodas. 2) From experience you know that 83% of the desks in the schools have gum stuck beneath them. In a random sample of 14 desks. a) Compute the probability that all of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT