Question

This is LU deposition code of matlab. What's wrong with this code.... Thank you n and...

This is LU deposition code of matlab. What's wrong with this code.... Thank you

n and B was given from above, what is
for i = 1:n
U(1,i) = A(1,i);
L(i,1) = A(i,1)/U(1,1); %u(1,1)=1
end

for j = 2:n
for k = j:n
U(j,k) = A(j,k)-L(j,1:j-1)*U(1:j-1,k);
L(k,j) = (A(k,j)-L(k,1:j-1)*U(1:j-1,j))/U(j,j);
end
end


for i = 1:n
x(i) = B(i) / L(i,i:n)*U(i:n,i);
end

fprintf("Ans x = \n");
fprintf("%f \n", x);

Homework Answers

Answer #1

y=zeros(m,1); % initiation for y

y(1)=B(1)/L(1,1);

for i=2:m

%y(i)=B(i)-L(i,1)*y(1)-L(i,2)*y(2)-L(i,3)*y(3);

y(i)=-L(i,1)*y(1);

for k=2:i-1

y(i)=y(i)-L(i,k)*y(k);

end;

y(i)=(B(i)+y(i))/L(i,i);

end;

y

% Now we use this y to solve Ux = y

x=zeros(m,1);

x(m)=y(m)/U(m,m);

i=m-1;

q=0;

while (i~= 0)

x(i)=-U(i,m)*x(m);

q=i+1;

while (q~=m)

x(i)=x(i)-U(i,q)*x(q);

q=q+1;

end;

x(i)=(y(i)+x(i))/U(i,i);

i=i-1;

end;

x

Another program that you can use :

function[L,U,X]=LU_Parker(A,B)
[m n]=size(A);
if (m ~= n )
disp ( 'LR2 error: Matrix must be square' );
return;
end;
% Part 2 : Decomposition of matrix into L and U
L=zeros(m,m);
U=zeros(m,m);
for i=1:m
% Finding L
for k=1:i-1
L(i,k)=A(i,k);
for j=1:k-1
L(i,k)= L(i,k)-L(i,j)*U(j,k);
end
L(i,k) = L(i,k)/U(k,k);
end
% Finding U
for k=i:m
U(i,k) = A(i,k);
for j=1:i-1
U(i,k)= U(i,k)-L(i,j)*U(j,k);
end
end
end
for i=1:m
L(i,i)=1;
end
% Program shows U and L
U
L
% Now use a vector y to solve 'Ly=b'
y=zeros(m,1);
y(1)=B(1)/L(1,1);
for i=2:m
y(i)=-L(i,1)*y(1);
for k=2:i-1
y(i)=y(i)-L(i,k)*y(k);
y(i)=(B(i)+y(i))/L(i,i);
end;
end;
% Now we use this y to solve Ux = y
x=zeros(m,1);
x(1)=y(1)/U(1,1);

for i=2:m
x(i)=-U(i,1)*x(1);

for k=i:m

x(i)=x(i)-U(i,k)*x(k);
x(i)=(y(i)+x(i))/U(i,i);
end;

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Code in Matlab. I need to make a diamond shape with * I get part of...
Code in Matlab. I need to make a diamond shape with * I get part of it with the code below. Instructions are: " Given the value of N print diamond of N + (N-1) rows. For example, if N = 5 it should print a diamond." clc clear n = input ('number of rows \n') o = input ('number of inverted rows \n') t = (o-1) for i = 1:n for k = 1:n-i fprintf (' '); end for...
IN C++ VERY EASY What's wrong with this code? The following function prints a reverse half-pyramid...
IN C++ VERY EASY What's wrong with this code? The following function prints a reverse half-pyramid populated by the alternating dots and stars (see example below). The odd rows contain stars and even rows contain dots. Debug the code to fix all the compilation and run-time errors, so that the code generates the desired output. For instance, when the 'n' value passed to the function is 6, the output would look like the following. ****** ..... **** ... ** ....
Problem 3 you can use Matlab and also i give u the Problem 1 code its...
Problem 3 you can use Matlab and also i give u the Problem 1 code its on Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandpass filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce this is the Problem 1 code and the solutin clear; clc;...
Why it cannot display flop? you need to explain rather than just show me another code...
Why it cannot display flop? you need to explain rather than just show me another code MatLab function b=Matrixvector(A,x) n=length(x); b=zeros(n,1); flop=0; for i=1:n for j=1:n b(i)=b(i)+A(i,j)*x(j); flop=flop+2; end end disp(b); disp(flop);
Can you rewrite this MATLAB code using a while loop instead of a for loop? %formatting...
Can you rewrite this MATLAB code using a while loop instead of a for loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
1. Given a matrix variable "mat", write code using for loops, if statements, etc. that will...
1. Given a matrix variable "mat", write code using for loops, if statements, etc. that will accomplish the same as the following: matsum = sum(mat') Please make sure to store the result in "matsum" and dont use sum. This is what I have so far but it keeps telling me is wrong.... % mat has been initialized for you: mat = randi([-100,100],randi([15,20]),randi([15,20])); % write your statements that accomplish the code above: [r c]=size(mat); for i=1:c matsum=0; for j=1:r matsum=matsum+mat(j,i); end...
USING MATLAB Code for pseudo Random Input N M=0 For i=1 to N X=rand# Y=rand# If...
USING MATLAB Code for pseudo Random Input N M=0 For i=1 to N X=rand# Y=rand# If X^2+ y^2 <= 1, then M=M+1 End the loop Print M/N (This is the probability) Print M/N (this is approximately = Py
MATLAB save output as array this is my code so far, I'm going to need to...
MATLAB save output as array this is my code so far, I'm going to need to save these as arrays or vectors i think to take some statistics on them. how do i save each walkers position relitive to time I should end up with 1000x 1000 matrix i think or 1000 arrays walkers=1000; %walkers=input('how many walkers do you want to simulate?') N = 1000; %N = input('how many steps do you want?') for k= 1:walkers displacement= randn(1,N); x =...
what did i do wrong in here? error said I have wrong code for scatter(rate(:,1),rate(:,5),'o') but...
what did i do wrong in here? error said I have wrong code for scatter(rate(:,1),rate(:,5),'o') but when I solved it, other codes are messed up how to solve it? datacell = textscan( regexprep( fileread('cricketData.csv'), '\$', '0' ), '%f%f', 'delimiter', ',', 'HeaderLines', 1); Duration = datacell{1}; Input = datacell{1}; YourTable = table(Duration, Input); temp=datacell(:,1); rate=datacell(:,2); scatter(rate(:,1),rate(:,5),'o') xlabel('temperature(T in degrees Fahrenheit)') ylabel('chirping (R in chirp per second))') title('Chirping rate vs Temperature') p=polyfit(rate(:,1),rate(:,2),1); x=min(1)-2:.01:max(2)+2; hold on plot(x,polyval(p,x)) legend('Data points,''best fit equation') fprintf('Calculated equation:...
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete...
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete frequencies ranging from 0 to 0.2 with a sampling frequency of 8 kHz. clear; Fs = 8000; Nbits = 16; tMax = 10; N = Fs*tMax+1; f = linspace(0.0,0.2,N); x = zeros(f); phi = 0; for n=0:N-1 x(n+1) = 0.8*sin(phi); phi = phi+2*%pi*f(n+1); end sound(x,Fs,Nbits); sleep(10000); //allows full sound to play Add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT