1 SE1PES: PROGRAMMING FOR ENGINEERS AND SCIENTISTS ASSIGNMENT 2 (10%) Assignment developed by Matthew Felicetti 2016, updated 2017(MF), updated 2018(MF) TOOLS • Unix server through Putty for compiling...

file attached


1 SE1PES: PROGRAMMING FOR ENGINEERS AND SCIENTISTS ASSIGNMENT 2 (10%) Assignment developed by Matthew Felicetti 2016, updated 2017(MF), updated 2018(MF) TOOLS • Unix server through Putty for compiling and testing • Notepad ++ for writing solutions • LMS for submission SUBMISSION o Submitted as a .c file in the normal assignment submission portal. (Do not submit the executable.) There is NO late submissions for this assignment. No assignment will be accepted after the due date, without a legitimate extension granted by the lecturer before the due date. ACADEMIC INTEGRITY Plagiarism is the submission of somebody else’s work in a manner that gives the impression that the work is your own. For individual assignments, plagiarism includes the case where two or more students work collaboratively on the assignment. The School of Engineering and Mathematics treats plagiarism very seriously. When it is detected, penalties are strictly imposed. http://www.latrobe.edu.au/students/academic-integrity http://www.latrobe.edu.au/students/academic-integrity 2 IMPEDANCE, VOLTAGE AND CURRENT CALCULATOR FOR SIMPLE AC CIRCUIT BACKGROUND An Alternating Current (AC) circuit is one in which the output of the voltage source changes with time. When we add components to the circuit, the voltage and current will be different at different points in the circuit. The components we will be looking at are resistors, capacitors and inductors. Further information can be found here: https://en.wikipedia.org/wiki/Alternating_current, https://en.wikipedia.org/wiki/Inductor, https://en.wikipedia.org/wiki/Resistor, https://en.wikipedia.org/wiki/Capacitor. Impedance is the measure of the resistance and reactance of a component or circuit. Resistance is a measure of friction against the motion of electrons, whereas reactance is the inertia against the motion of electrons. Impedance introduces a phase shift between the voltage and current through a component, and hence is expressed as a complex number. Do not worry too much if this doesn't make sense, you can just think of this as complex resistance. For further information, please read https://en.wikipedia.org/wiki/Electrical_impedance. To calculate the impedance, voltage and current for each component in the circuit, we can use ohms law. The equation for ohms law is as follows: (Note we are dealing with complex numbers, however we will develop all the necessary functions you will need in lab 5) ?? = ?? ∗ ?? , ?? = ?? ?? ,?? = ?? ?? Where V, I and Z represent voltage, current and impedance respectively, and are measured in volts, amps and ohms respectively. For series circuits the current is the same through all components. For parallel circuits the voltage is the same through all components. The impedance calculation depends on the component. Details are as follows: Resistors: The impedance for a resistor can be found as: ?? = ?? where R is the resistance measured in ohms. Capacitors: The impedance for a capacitor can be found as: ???? = 1 2∗??∗??∗?? where C is the capacitance measured in Farads and f is the frequency measured in hertz ?? = 0 − ?? ∗ ???? where ???? is the reactance and j is the imaginary unit. Inductors: The impedance for an inductor can be found as: ???? = 2 ∗ ?? ∗ ?? ∗ ?? where L is the inductance measured in Henrys ?? = 0 + ?? ∗ ???? where ???? is the reactance and j is the imaginary unit. 3 Components will either be arranged in parallel or series. Depending on this, the total impedance calculation will vary. The total impedance between two components in series is: ???? = ??1 + ??2 If we have three components in series, then the total impedance is: ????2 = ???? + ??3 Hence, generalizing this we get: ???? = �???? ?? ??=1 The total impedance between two components in parallel is: ???? = � 1 ??1 + 1 ??2 � −1 Which we can then extend to calculate for three components by: ????2 = � 1 ???? + 1 ??3 � −1 Hence, generalizing this we get: ???? = �� 1 ???? ?? ??=1 � −1 4 PROBLEM You are to create a program that allows a user to view the voltage, current and impedance for each component and the total in either the parallel circuit (a) or series circuit (b). The program will ask the user for the circuit type, the source voltage, the frequency, the number of components, and the values of each component. The two circuits are shown below: a. Parallel circuit b. Series circuit 5 MAKE SURE YOU UNDERSTAND THE WORKED EXAMPLE BEFORE STARTING ANYTHING YOU DO NOT UNDERSTAND IN THE MATH PUT ON THE FORUM Worked Example: Given a parallel circuit (a), with a source voltage of 12Vpp, a frequency of 60Hz, with 3 components in parallel. The components are a 40 ohm resistor, a 0.0003 farad capacitor and a 0.2 henry inductor. Firstly we calculate the impedance of each component: ????(?????????????????? ???? ????????????????) = 40 ??ℎ???? ????(?????????????????? ???? ??????????????????) = 0 − 1 2 ∗ ?? ∗ 60 ∗ 0.0003 ∗ ?? = 0 − 8.842?? ??ℎ???? ????(?????????????????? ???? ????????????????) = 0 + 2 ∗ ?? ∗ 60 ∗ 0.2 ∗ ?? = 0 + 75.4?? ??ℎ???? We now calculate the total impedance. As we are using a parallel circuit we use the formula as above. We calculate the summation first as follows: � 1 ???? ?? ??=1 = � 1 ???? + 1 ???? + 1 ???? � = 1 40 + 1 −8.842?? + 1 75.4?? = 40 402 − 8.842 8.8422 j + 75.4 75.42 j ≈ 0.025 + 0.1131j− 0.0133j ≈ 0.025 + 0.0998j Then find the reciprocal to get the total impedance: ???? = �� 1 ???? ?? ??=1 � −1 ≈ 1 0.025 + 0.0998j 6 ≈ 0.025 0.0252 + 0.09982 + ?? −0.0998 0.0252 + 0.09982 ≈ 2.36 − ??9.429 We then calculate the total current using Ohms law ?? = ?? ?? = 12 2.36 − 9.429?? = 0.3 + 1.198?? ???????? We then know that voltage is the same throughout the circuit because all the components are in parallel. So we only need to calculate the current for each component: ???? = 12 40 = 0.3 ???????? ???? = 12 −8.842?? = 1.357?? ???????? ???? = 12 75.4?? = −0.159?? ???????? Hence we can now generate the table: COMPONENTS R C L TOTAL Z ( Ohms) 40+0j 0-8.842j 0+75.4j 2.36− 9.425?? I (Amps) 0.3+0j 0+1.357j 0-0.159j 0.3+1.198j V (Volts) 12+0j 12+0j 12+0j 12+0j 7 FUNCTION PROTOTYPES AND INCLUDES 1. You must include the stdio.h and stdlib.h libraries. No other libraries can be used 2. The following function prototypes are to be used: a. The first two are described below b. The last four will be developed in lab5, you need to alter the types from floats to doubles c. You can change the naming d. You cannot change the types 8 FUNCTION - MAIN 1. The program prints to the screen the student number, student name and the assignment number. This is enclosed by double asterisks. Ensure you follow the below format. 2. The program asks the user which circuit they want to evaluate, the frequency in hertz, the source voltage and the number of components. And stores the results appropriately. All of these values are positive integers. When asking for the number of components, the type of circuit should be specified as shown below. a. You can assume the user enters valid values for frequency, voltage and number of components. a. You must handle the case where the user enters an incorrect value for the type of circuit and give a message to the user. (No example given, a single line for ‘invalid message’ to user ending with a newline. The message is up to you, but must be appropriate) If the user enters an incorrect value, print the message, and ask them again. (i.e. should they use a loop to keep asking for a valid type of circuit 9 3. The program creates the following 6 pointers to doubles variables (These combined forms the result table) (Do not create a two dimensional array or you will be awarded zero for the assignment.) a. Then dynamically allocate memory (malloc) for each of the pointers as an array of size sizeof(double) *(number of components + 1) (The +1 is for the total) b. Then the program stores the source voltage in the array as shown below 0 1 … number of components -1 number of components result_table_impedance_real 0 Impedance component 1 – Real part Impedance component 2 – Real part … Impedance component n – Real part Total Impedance - Real part result_table_impedance_imag 1 Impedance component 1 – Imaginary part Impedance component 2 – Imaginary part … Impedance component n – Imaginary part Total Impedance - Imaginary part result_table_current_real 2 Current component 1 – Real part Current component 2 – Real part … Current component n – Real part Total Current – Real part result_table_current_imag 3 Current component 1 – Imaginary part Current component 2 – Imaginary part … Current component n – Imaginary part Total Current – Imaginary part result_table_voltage_real 4 Voltage component 1 – Real part Voltage component 2 – Real part … Voltage component n – Real part Total Votage/Source Voltage – Real part result_table_voltage_imag 5 Voltage component 1 - Imaginary part Voltage component 2 – Imaginary part … Voltage component n – Imaginary part Total Votage/Source Voltage – Imaginary part 10 4. The program dynamically allocates memory for an array of ints of length number of components, and an appropriate pointer is created named components which points to the start of the
May 09, 2020
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here