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

Create a script for the following problem An engineer had measured impedances of

ID: 3723335 • Letter: C

Question

Create a script for the following problem An engineer had measured impedances of a collection of electrical components and created a text file - impedance.txt - based on the numerical data. You will find that impedance.txt file is MAGNITUDE of the impedance and the second row is the PHASE (in radian) of the impedance. components . The first row of the number indicates the number of Column Here are the needed conditions (1) will read the impedance.txt and find the nmber (You can use 'size' function) (2) compute real part and imaginary part of impedance of individual component (3) Save the result on a variable Impedance_Catesian. (4) Save the result on a text file Impedance_Cartesian.txt (5) Also have this following message displayed on the screen ("There are ### components in the file impedance.txt. The Conversion of POLAR format of complex number into CARTESIAN format is completed and the result is saved on Impedance_Cartesian.txt") (6) Do this with FOR LOOP OR WHILE LOOP (Only a single script is needed!) column Conversion Equation from Polar into Cartesian From MAGNITUDE PHASE ANGLE REAL +jIMAGINARY REAL = MAG * cos(PHASE ANGLE) IMAGINARY = MAGNITDE * sin(PHASE ANGLE)

Explanation / Answer

Code:

clear all
fileID = fopen('Impedtext.txt','r');
a=0;
b=1;
m=1;
n=1;
while a~=-1
a=fgetl(fileID);
if a==-1
break
end
temp=str2num(a);
if mod(n,2) == 1
for i=1:length(str2num(a))
mag(b,i)=temp(i);
end
b=b+1;
end
if mod(n,2) == 0
for i=1:length(str2num(a))
phase(m,i)=temp(i);
end
m=m+1;
end
n=n+1;
end
[b,m]=size(mag);

for i=1:b
for n=1:m
Impedance_Cartesian(i,n)=(mag(i,n)*cos(phase(i,n))+(mag(i,n)*sin(phase(i,n)))*1j);
end
end
[b,m]=size(Impedance_Cartesian);
z_real = real(Impedance_Cartesian);
z_imag = imag(Impedance_Cartesian);
a=num2str(Impedance_Cartesian);
formatSpec = '%6.4f %6.4f*i ';
fileID = fopen('ImpCartesian.txt', 'w');
for i=1:length(b)
fprintf(fileID,formatSpec,real(Impedance_Cartesian),imag(Impedance_Cartesian));
end
fprintf(['These strings are ' num2str(m) ' components in the file. POLAR Conversion of complex number into CARTESIAN format is saved into ImpCartesian.txt'])

Hiiii...Feel free to contact for further Queries

Please vote me up if you like my Answer.

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