DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: AC circuit analysis program

1. Registered User
Join Date
Apr 2004
Posts
5

## help on C++

hello
i just want to know if some one could help me with the C++ programming. i really need it.
here is the program:
In AC circuit analysis, the general form of the equations for the variation in voltage vs time is given by the following expressions:
V1 = Vm * sin(w*t +angle)
V2= Vm *cos(w*t+angle)
where
Vm is the maximum positive amplitude (peak value) of the voltage
angle is the phase angle in degrees
w is the angular velocity in radians/sec, and is equal to
f is the frequency of the wave in Hertz
is to be defined as a constant variable whose value is 3.1415926
Write a C++ program that uses a function to input the values of V1 ,V2 , and . The program will then display the values of and in a 2-dimensional array for the various values of time indicated below. Use the following procedure:

From the input frequency, f , calculate the period, T, of the waveform by .
Multiply the period by 2 to obtain two complete cycles.
Convert the phase angle, , from degrees to radians by .
Establish a loop to calculate and output the values of and for each of the above equations. The time variable, , will increment in equal steps from to for 100 values of . This is called a time sweep.
At the beginning of the output, print out the values of vm ,w ,angle , T, and , and the RMS voltage of the waveform. The Vrms is calculated by Vrms * 0.707 . The output will contain the 100 calculated values for both equations listed in a column with appropriate header information.
Demonstrate that your program works by using the following cases as a minimum:
Vm angle frequency

100 V 0 10 kHz
50 V 37 5 kHz
75 V - 43 0.8 kHz

After the output is created, plot every 5th value for and on a sheet of graph paper for each of the above cases (as a minimum). Use a different color for each wave. That is, on each sheet of graph paper, plot both waves in a different color, but both on the same plot. As a result, you should have three plots (as a minimum) when finished. If you wish, you can use a plotting program to create the plots. On each plot indicate which case you are plotting and all pertinent values.

Note:
The 2-dimensional array showing values of V1 and V2 for the various values of time might look like the one below (table shows hypothetical values for time and voltages):

Time [microseconds] [Volts] [Volts]
0 0 100
0.3 3 97
0.6 7 93
--- ---- ----
--- ---- ----

i got the part that we ask from the user to input values
the only thing i don't get is the 2-dimensional array,
DOES ANYONE KNOW HOW TO DO IT.
THANKZZZZZZZ
BYE  Reply With Quote

2. Senior Member
Join Date
Dec 2003
Posts
3,366
its much like a single array.

int twod[rows] [cols];

for(x = 0; x < rows; x++)
for(y = 0; y < cols; y++)
twod[x][y] = something;

etc.  Reply With Quote

3. Registered User
Join Date
Apr 2004
Posts
5
thank you joinin

that is great thank you but i don't get that part when we put the t in the formula, to slove v1 and v2.
thank you
Last edited by helpme; 04-08-2004 at 10:51 AM.  Reply With Quote

4. Registered User
Join Date
Apr 2004
Posts
5
i don't get array, i don't understand it that well
so anyone plz help  Reply With Quote

5. Senior Member
Join Date
Dec 2003
Posts
3,366
I don't get it either, because the problem is chopped up. Entire phrases are missing in the instructions, or wherever you got it from is not in english.  Reply With Quote

6. Registered User
Join Date
Apr 2004
Posts
12
It seems that you want to solve some equations or systems, and then plot sth, isn't it?

Use MatLab.
And you can still use your existed code to get input from the user.

Someone said that MatLab can export C code.  Reply With Quote

7. Registered User
Join Date
Apr 2004
Posts
12
V1 = Vm * sin(w*t +angle)
V2= Vm *cos(w*t+angle)

You said: Write a C++ program that uses a function to input the values of V1 ,V2 , and . The program will then display the values of and in a 2-dimensional array for the various values of time indicated below.

Did you mean: Input the frequency, Vm and phase angle and get values of V1 and V2 for a range of time values? This would make sense. Usually Vm, w and the angle are constants, with t being the independent variable and V being the ouput of the function. The voltage is varying with time.

DJ  Reply With Quote

8. Registered User
Join Date
Apr 2004
Posts
12
Also,

w = 2*pi*f;
where f = 1/period;  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
• 