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

in matlab any code 2. (New) Create a script for the following problem. An engine

ID: 3591537 • Letter: I

Question

in matlab

any code

2. (New) 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 num data. You will find that impedance.txt on Canvas. The first Row of the file is MAGNITUDE of the impedance and the second Row is the PHASE in radian) of the impedance. Column number indicates the number of components erical Here are the needed conditions. (1) will read the impedance.txt and find the Column number (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!) Conversion Equation from Polar into Cartesian From MAGNITUDE

Explanation / Answer

ANSWER:

%matlab code

Please find the Matlab Program for the Question 2 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

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

%---------Question2.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));

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

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

%--------Question2.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"']);


%--------Question2.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-------------