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

1) Create an m-File (Not function) An engineer had measured impedances of a coll

ID: 3590995 • Letter: 1

Question

1) Create an m-File (Not function) 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 on Canvas. The first column of the file is real part of the impedance and the second column is the imaginary part of the impedance Row number indicates the number of components What you should do Create m-file that (1) will read the impedance.txt and find the row number (You can use 'size' function) (2) compute magnitude and phase (angle) of impedance of individual component (3) Save the result on a variable Impedance_Polar (4) Save the result on a text file Impedance Polar.txt (5) Also have this following message displayed on the screen ("There are ### components in the file impedance.txt. The Conversion of Cartesian format of complex number into Polar is completed and the result is saved on Impedance Polar.txt") (6) Do this with FOR LOOP and WHILE LOOP (in other words, create two script one with for loop and one with while loop)

Explanation / Answer

%matlab code

Please find the Matlab Program for the Question 1.1 to 1.6 below. In this program, first we are loading the impedance.txt and then we are finding the madgnitude and phase using (1) Directly the Matrices, (2) Using For Loop, and (3) Using While Loop

-------START OF SOLUTION--------

clear;
impe=rand(5,2); save('impedance.txt','impe','-ASCII');
load('impedance.txt'); %first load the text file that contains the impedance values

%---------Question1.1-----------%
Number_of_components=size(impedance,1); %The number of components=Number od rows in the variable 'impedance'

%---------Question1.2-----------%
Impedance_Polar=zeros(size(impedance)); %Initate the variable Impedance_Polar which contains magnitude and phase of impedance all components to zero
magnitude=sqrt(impedance(:,1).^2+impedance(:,2).^2);
phase=atan(impedance(:,2)./impedance(:,1));

%--------Question1.3-----------%
Impedance_Polar(:,1) = magnitude;
Impedance_Polar(:,2) = phase;

%--------Question1.4----------%
save('Impedance_Polar.txt','Impedance_Polar','-ASCII');

%--------Question1.5----------%
display(['"There are ', num2str(Number_of_components), ' components in the file impedance.txt. The Conversion of cartesian format of complex number into Polar is completed and the result is saved in Impedance_Polar.txt"']);


%--------Question1.6---------%
%---------Using For loop---------%
load('impedance.txt'); %first load the text file that contains the impedance values

Number_of_components=size(impedance,1); %The number of components=Number od rows in the variable 'impedance'

Impedance_Polar=zeros(size(impedance)); %Initate the variable Impedance_Polar which contains magnitude and phase of impedance all components to zero
magnitude=zeros(Number_of_components,1);
phase=zeros(Number_of_components,1);
for i=1:Number_of_components
magnitude(i,1)=sqrt(impedance(i,1)^2+impedance(i,2)^2);
phase(i,1)=atan(impedance(i,2)/impedance(i,1));
end

Impedance_Polar(:,1) = magnitude;
Impedance_Polar(:,2) = phase;

save('Impedance_Polar.txt','Impedance_Polar','-ASCII');

display(['"There are ', num2str(Number_of_components), ' components in the file impedance.txt. The Conversion of cartesian format of complex number into Polar is completed and the result is saved in Impedance_Polar.txt"']);


%---------Using While loop---------%
load('impedance.txt'); %first load the text file that contains the impedance values

Number_of_components=size(impedance,1); %The number of components=Number od rows in the variable 'impedance'

Impedance_Polar=zeros(size(impedance)); %Initate the variable Impedance_Polar which contains magnitude and phase of impedance all components to zero
magnitude=zeros(Number_of_components,1);
phase=zeros(Number_of_components,1);
i=1;
while(i<=Number_of_components)
magnitude(i,1)=sqrt(impedance(i,1)^2+impedance(i,2)^2);
phase(i,1)=atan(impedance(i,2)/impedance(i,1));
i=i+1;
end

Impedance_Polar(:,1) = magnitude;
Impedance_Polar(:,2) = phase;

save('Impedance_Polar.txt','Impedance_Polar','-ASCII');

display(['"There are ', num2str(Number_of_components), ' components in the file impedance.txt. The Conversion of cartesian format of complex number into Polar is completed and the result is saved in Impedance_Polar.txt"']);

--------------END of SOULUTION-------------