Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 4. LU decompositon and the backslash Ucommand Consider the circuit diagr

ID: 2081729 • Letter: P

Question

Problem 4. LU decompositon and the backslash Ucommand Consider the circuit diagram below: Following the two rules: l. The voltage drop across a resistor is V IR; and 2. The sum of all voltage drops in a closed loop sum to zero Kirchhoff s Law), we can construct the following system ofequations: Let the resistances be given by R-50, -20 n, R-10 n. R.-40 n, and R-150. and let V be a variable voltage divider and V 30 v. I, I and I are to be solved given a value of Vi (a Write the equations in matrix form Ax-b.and determine the matrices P.L, and U using the lu command so that PA-LU. Save A, P, and L, and U. in that order, in A16.dat using Matlab's save ascii command. Vary vi from 50 to 100 in steps of 2 (ie, V 50, 52, 54 98, 100) and calculate L. and I, as a function of the increasing by solving the system above using P, L, and U and the backslash commands (ie. y Lsomething x-UA something). Save all the results in one 3x26 matrix, with the order of the columns following that of V. in A17.dat using Matlab's save -ascii command. (c Repeat (b) but use the inv command instead of lu and backslash Note that this way is slower than that of b) and there will be also numerical differences (tiny though) Calculate the absolute numerical differences. Save all the absolute differences in one 3x26 matrix. with the order of the columns following that of V in A18-dat, using Matlab's save -ascii command.

Explanation / Answer

code

clc
close all;
R1=5;
R2=20;
R3=10;
R4=40;
R5=15;
V2=-30;
syms V1 I1 I2 I3
V1=50;

eqn1=I1*(R1+R2)-R2*I2==V1;
eqn2=-I1*R2+I2*(R2+R3+R4)-R4*I3==0;
eqn3=-I2*R4+I3*(R4+R5)==-V2;

[a,b]=equationsToMatrix([eqn1, eqn2, eqn3],[I1,I2,I3]);

a1=double(a);
b1=double(b);
[L, U, P]=lu(a);
L1=double(L);%to save in ascii format we have to use convertt sym variable into double precisiion
U1=double(U);
P=double(P);

y1=P*a;
y2=L*U;

save A16.dat a1 b1 L1 U1 P1 -ascii

code for 2nd part

clc
close all;
R1=5;
R2=20;
R3=10;
R4=40;
R5=15;
V2=-30;
syms V1 I1 I2 I3

V1= 50:2:100;
eqn1=zeros(1,length(V1));
x=zeros(1,length(V1));%defining the length of x
r=zeros(3,length(V1));%defining the r matrix as of size 3 by length(V1)
for v=1:1:length(V1)
eqn1=I1*(R1+R2)-R2*I2==V1(v);
eqn2=-I1*R2+I2*(R2+R3+R4)-R4*I3==0;
eqn3=-I2*R4+I3*(R4+R5)==-V2;

[c,d]=equationsToMatrix([eqn1, eqn2, eqn3],[I1,I2,I3]);

[L1, U1, P1]=lu(c);

y=L1d;
x=U1y;%solution of current matrix by L u factorization
r([1 2 3],[v])=x;%final result here each column of r will store the solution of current for V1=50 to 100

end

r1=double(r);
save A17.dat r1 -ascii

code for third part

clc
close all;
R1=5;
R2=20;
R3=10;
R4=40;
R5=15;
V2=-30;
syms V1 I1 I2 I3

V1= 50:2:100;
eqn1=zeros(1,length(V1));
x=zeros(1,length(V1));
r1=zeros(3,length(V1));%defining the r matrix as of size 3 by length(V1)
for v=1:1:length(V1)
eqn1=I1*(R1+R2)-R2*I2==V1(v);
eqn2=-I1*R2+I2*(R2+R3+R4)-R4*I3==0;
eqn3=-I2*R4+I3*(R4+R5)==-V2;

[e,f]=equationsToMatrix([eqn1, eqn2, eqn3],[I1,I2,I3]);

[L2, U2]=lu(e);


x1=inv(U2)*inv(L2);%finding the inverse of matrix e by the inv formula
x2=x1*f;%final solution of current value for each V1
r1([1 2 3],[v])=x2;%final result here each column of r will store the solution of current for V1=50 to 100


end

r2=double(r1);
save A18.dat r1 -ascii

it is better to see if u save the file in txt file instead of dat just replace .dat with .txt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote