Assignment Qasim

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

ANALYSIS:

To Design A Code To Calculate The Minimum Loss Of The Ciruit Given In The Coursework To
Caculate Minimum Loss Of Circuit We Have T0 Calculate The The Resistance In The Circuit Which Are
Mentioned As R1 And R2
First Of The Program Conists Of Four Function And One Main Program File The Program Has Separate
Function For Each Calculation Named As
Calcr1 (To Calculate Resistance R1)
Calcr2 (To Calculate Resistance R2)
Minimumloss (To Calculate Minmumloss )
And One Fucntion Named As Programmain(Used To Get User Input And Calls The Other Functions)
The Code Starts BY CALLING THE MAINprogram function to Ask User To Enter Z And Z1 The
Impedences Then Check Whether The Condition Are Met If Condition Does Not Met Thenprogram Ask
Again The User To Enter Again Then Program Cals All Three Function And Calculate The Values And
Display And Then Ask The User If They Want To Repeat The Task Then Press Y If Not Press N if user
press Y the program starts from start and if user press N the program terminate the program

CODE:
MAIN SCRIPT:
clc;
clear all;
programmain(); %all the input from user and displa calculation
%code to ask user whether he wants t repeat or not
while(1)
disp ('if do you want to repeat the task')
c=input('please select Y/N:','s')
if (strcmpi(c,'Y')) %compares the input with y
programmain();
elseif(strcmpi(c,'N')) %compares the input with x
break
end
end

FUCNTION PROGRAMMAIN:
function []=programmain()
disp("WELCOME")
z=input('please enter the value for z1')
z1=input('please enter the value for z')
while(z1<=0 || z<=0 || z<z1) %ask user to nput correct values
disp('invalid input please read the following instructon')
disp('NOTE:BOTH z1 and z must be annteger and z1 must be smaller than z')
z=input('please enter the value for z1')
z1=input('please enter the value for z')
end
R1=calcR1(z,z1); %calls the function calcR1 to calculate R1 and saves the
value in R1
R2=calcR2(z,z1);%calls the function calcR2 to calculate R2 and saves the value
in R2
LM=minimumloss(z,z1);%calls the function minimumloss to calculate R2 and saves
the value in R2
fprintf('resistance R1 is= \n')
disp(R1)%displays the calculated R1
fprintf('resistance R1 is= \n')
disp(R2)%displays the calculated R2
fprintf('resistance R1 is= \n')
disp(LM)%displays the calculated minimumloss
return

FUNCTION CALCR1
function [R1]=calcR1(z,z1)
r1=z1*(sqrt(1-(z1/z)));
R1=r1;
return

FUNCTION CALCR2
function [R2]=calcR2(z,z1)
r2=z1/(sqrt(1-(z1/z)));
R2=r2;
return

FUCNTION minimumloss
function [Lm]=minimumloss(z,z1)
x=sqrt(z1/z);
y=sqrt((z/z1)-1);
lm=20*log10(x+y);
Lm=lm;
return

You might also like