|
johnzfrebbies@ wrote: I still have not got the program to display the answers whether correct or incorrect.
I'm not sure why - the code I posted worked perfectly.
johnzfrebbies@ wrote: I'm also trying to get user input by typing file name&num so I can read in that file and compare it to the answers. also I will finish it off with a MAXSIZE array in case the exam consists of more than 20 questions. what I need the most is some help with the syntax for the input from user that consists of NameNum.dat
If I understand you correctly, you want the user to input the name of the file to be read. We'll be consistent and use ifstream although there are other file functions one could use. We can proceed as follows.
We need to pass a FileName to ifstream . The FileName is, of course the name of the file we want to open for reading.
First we need an array to hold the file name the user inputs. We'll be consistent with the rest of your program and use an array of size 20:
char FileName[20];
At this point you need to use cout and cin to get the filename from the user. I think you can write the code for that. Finally, we'll use your existing Answers ifstream for reading:
ifstream Answers;
Answers.open(FileName);
It's a good idea to check that the file name we entered corresponds to an existing file. We can do that by checking to see if Answers is NULL :
if (!Answers)
{
cout << "Cannot open file." << endl;
system("PAUSE");
exit(1);
}
Putting it all together:
char FileName[20];
cout << "Enter a filename: ";
cin >> FileName;
ifstream Answers;
Answers.open(FileName);
if (!Answers)
{
cout << "Cannot open file." << endl;
system("PAUSE");
exit(1);
}
Of course you can modify this to suit your specific needs, but that's just a basic way to read in a file and get input from it. You could do something different than exit the program if the input file name isn't valid. For example, you could prompt the user to enter another name.
Hope that helps!
|
|
|
|
|
hey Thanks! The code you posted works great and gave me a better understanding by example. Thats what I need to fully understand what I'm doing.
I'll post my full code later today with the modifications, just so and if anyone else needs an example they can be directed to. Thanks again for your help.
|
|
|
|
|
johnzfrebbies@ wrote: hey Thanks! The code you posted works great and gave me a better understanding by example. Thats what I need to fully understand what I'm doing.
I'll post my full code later today with the modifications, just so and if anyone else needs an example they can be directed to. Thanks again for your help.
Okay, great. Glad it worked out.
|
|
|
|
|
hello a question about desktops if you don't mind...do you have any recommendations other than what I use (yod'm 3D) I'd like to have something like beryl, but I'm not using the installed version of Ubuntu 8.04 (it runs atop xp as beta on 1 of the desktops) I like the switching desktops, I just need more functions. Do you know any other functions or maybe just another program?
|
|
|
|
|
johnzfrebbies@ wrote: hello a question about desktops if you don't mind...do you have any recommendations other than what I use (yod'm 3D) I'd like to have something like beryl, but I'm not using the installed version of Ubuntu 8.04 (it runs atop xp as beta on 1 of the desktops) I like the switching desktops, I just need more functions. Do you know any other functions or maybe just another program?
Oh geez, no idea. That's a little out of my realm of experience. I used Linux back in the late 90's early 2000's. I think it was Enlightenment that I used to run and occasionally Gnome. Now I mostly use XP on a Dell laptop. I also have a Mac that I do some cross-testing on. I just go with the standard desktops out of the box. Hmmm, you could try asking in the Lounge and see if someone recommends something.
|
|
|
|
|
Problem:
<br />
Let w = 2000<br />
V = 6V<br />
L = 0.2H<br />
R = 400<br />
<br />
Given the differential equation L*(di/dt) + R*i = V*cos(w*t)<br />
<br />
Find i(t). - The above equation is true for t = 0<br />
<br />
This is what I have come up with. - NOTE: When im integrating ive used the '!' symbol
I solved the above using the steady state and transient method.
For the transient part:
<br />
-> 0.2*(di/dt) + 400*i = 6*cos(w*t) <br />
-> (di/dt) + 2000*i = 30*cos(w*t) <br />
<br />
-> di/dt + 2000*i = 0 <br />
<br />
-> di = -2000*i*dt<br />
<br />
-> !(1/i)*di = !-2000*dt ('!' means integrate)<br />
<br />
-> ln(i) = -2000t + c<br />
<br />
-> i(transient) = e^(-2000t)*e^c<br />
<br />
Let e^c = A (a constant)<br />
<br />
-> i(transient) = A*e^-2000t<br />
For the steady state part:
Ohms law states that the current i = V/Z, where V is voltage, and Z is impedance.
So, V = 6>0 V The '>' is the polar form (or phasor some might know it as) representation of the complex angle associated with the voltage, so 6V, 0 angle.
<br />
Z = R + j*w*L<br />
Z = 400 + j*2000*0.2<br />
Z = 400 + j400<br />
Z = 565.685>0.785 (all angles are in radians)<br />
<br />
-> i = V/Z<br />
<br />
-> i = 6>0 / 565.685>0.785<br />
<br />
-> i = 10.61>-0.785 mA<br />
<br />
-> i(steady state) = 10.61*sin(w*t - 0.785) mA<br />
Now to find the final equation for i(t)
<br />
To derrive i(t):<br />
<br />
-> i(t) = i(steady state) + i(transient)<br />
<br />
-> i(t) = A*e^-2000t + 10.61*sin(w*t - 0.785) mA <br />
<br />
To find A make t = 0<br />
<br />
-> i(0) = A(1) + (10.61*10^-3)*sin(-0.785)<br />
<br />
-> 0 = A - 7.5*10^-3<br />
-> A = 7.5*10^-3<br />
<br />
So the final equation for i(t) is:<br />
<br />
-7.5*e^-2000t + 10.61*sin(w*t - 0.785) mA<br />
<br />
However this is not working out - I should be able to substitute this equation back into the original:
<br />
<br />
-> L*(di/dt) + R*i = V*cos(w*t)<br />
<br />
L = 0.2<br />
R = 400<br />
i(t) = 7.5*e^-2000t + 10.61*sin(2000*t - 0.785) mA<br />
i'(t) = -15*e^-2000t + 21.22*cos(2000*t - 0.785)<br />
V = 6<br />
<br />
-> 0.2*(-15*e^-2000t + 21.22*cos(2000*t - 0.785)) + 400((7.5*10^-3)*e^-2000t + (10.61*10^-3)*sin(2000*t - 0.785)) = 6*cos(2000*t)<br />
<br />
Let t = 1<br />
<br />
-> 0.2(0 + 8.434) + 400(0 + (9.8677*10^-3)) = 6cos(2000)<br />
<br />
-> 1.6869 + 3.947 = -2.205<br />
<br />
This does not satisfy the equation!!!<br />
<br />
Can anyone see where I went wrong in my working?
[Edit] - Fixed a typo.
Cheers,
modified on Tuesday, April 22, 2008 10:28 AM
|
|
|
|
|
Looks to me like you're missing an exponential term. You only have one. The generalized solution to an equation of your type is:
/ R t 2 R t 2 2 \
|exp(- ---) C1 R + exp(- ---) C1 w L + V sin(w t) w L + V cos(w t) R|
\ L L /
/ 2 2 2
/ (R + w L )
/
You should check your transient solution and make sure you've solved for the integration properly. Did you omit a term?
And when the sunlight hits the olive oil, don't hesitate.
|
|
|
|
|
Oh geez mate i've never seen that equation before!
I got my answer by following a worked solution:
<br />
<br />
(di/dt) + 1000i = 10cos(wt)<br />
<br />
What is the transient part of the solution?<br />
<br />
The transient part satisfies the DE di/dt + 1000i = 0.<br />
<br />
Let i(transient) = A*e^(theta *t)<br />
<br />
di = -1000i*dt<br />
!(1/i)*di = !-1000*dt where ! means integral<br />
ln(i) = -1000t + c<br />
i = e^(-1000*t)*e^c<br />
<br />
Let e^c = A<br />
<br />
-> i = A*e^(-1000*t).<br />
<br />
This example was given to me in class, so I assume that it is the method they want me to follow.
Cheers,
|
|
|
|
|
Your final line of your transient solution:
-> i(transient) = e^-2000t + e^c
-> i(transient) = A*e^-2000t
ln i = -Rt/L + C
i = exp(-Rt/L + C)
which does not equal: exp(-2000t) + exp(C)
it equals exp(-2000t + C)
Try fixing that...
Sorry, I see you've got A*exp(-2000t) there...okay.
And when the sunlight hits the olive oil, don't hesitate.
|
|
|
|
|
Yea sorry that was a typo on my part. I was meant to write that as:
<br />
i(transient) = e^(-2000t+c)<br />
i(transient) = e^(-2000t)*e^c<br />
<br />
Let e^c = a constant A<br />
<br />
i(transient) = A*e^(-2000t)<br />
That typo does not effect any working following it, as the next line corrected the error.
Cheers,
|
|
|
|
|
MarkBrock wrote: -> (di/dt) + 2000*i = 30*cos(w*t)
-> di/dt + 2000*i = 0
Uhm.............
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
From my notes, given the DE -> (di/dt) + 1000i = 10cos(wt)
What is the transient part of the solution?<br />
<br />
The transient part satisfies the DE di/dt + 1000i = 0
|
|
|
|
|
Ah, then, it's OK. I didn't remember the definition.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
MarkBrock wrote: -> i = 6>0 / 565.685>0.785
I think the V phase is wrong. It should be PI/2 instead of 0 .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yes I think so too...
And when the sunlight hits the olive oil, don't hesitate.
|
|
|
|
|
It's comforting: I don't remember a lot of that stuff...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yup that was it!
t=1 and t=0.1 both worked so im satisfied with that.
<br />
<br />
-7.5*e^-2000t + 10.61*sin(w*t + 0.785) mA<br />
<br />
<br />
-> L*(di/dt) + R*i = V*cos(w*t)<br />
<br />
L = 0.2<br />
R = 400<br />
i(t) = -7.5*e^-2000t + 10.61*sin(2000*t + 0.785) mA<br />
i'(t) = 15*e^-2000t + 21.22*cos(2000*t + 0.785)<br />
V = 6<br />
<br />
-> 0.2*(15*e^-2000t + 21.22*cos(2000*t + 0.785)) <br />
+ 400((-7.5*10^-3)*e^-2000t + (10.61*10^-3)*sin(2000*t + 0.785))<br />
= 6*cos(2000*t)<br />
<br />
Let t = 1<br />
<br />
-> 0.2(0 -19.46) + 400(0 + (9.8677*10^-3)) = 6cos(2000)<br />
<br />
-> -3.893 + 1.6898 = -2.2<br />
-> -2.2 = -2.2<br />
<br />
Horray! <br />
<br />
Thankyou so much for your help!
Cheers,
|
|
|
|
|
You're welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Did you work it out?
And when the sunlight hits the olive oil, don't hesitate.
|
|
|
|
|
Yup that was it!!!
t=1 and t=0.1 both worked so im satisfied with that.
<br />
<br />
-7.5*e^-2000t + 10.61*sin(w*t + 0.785) mA<br />
<br />
<br />
-> L*(di/dt) + R*i = V*cos(w*t)<br />
<br />
L = 0.2<br />
R = 400<br />
i(t) = -7.5*e^-2000t + 10.61*sin(2000*t + 0.785) mA<br />
i'(t) = 15*e^-2000t + 21.22*cos(2000*t + 0.785)<br />
V = 6<br />
<br />
-> 0.2*(15*e^-2000t + 21.22*cos(2000*t + 0.785)) <br />
+ 400((-7.5*10^-3)*e^-2000t + (10.61*10^-3)*sin(2000*t + 0.785))<br />
= 6*cos(2000*t)<br />
<br />
Let t = 1<br />
<br />
-> 0.2(0 -19.46) + 400(0 + (9.8677*10^-3)) = 6cos(2000)<br />
<br />
-> -3.893 + 1.6898 = -2.2<br />
-> -2.2 = -2.2<br />
<br />
Horray! <br />
<br />
Thankyou so much for your help!
Cheers,
|
|
|
|
|
Good!
MarkBrock wrote: Thankyou so much for your help!
No problem.
And when the sunlight hits the olive oil, don't hesitate.
|
|
|
|
|
MarkBrock wrote: ...and Z is impedance.
Back when I took electronics courses, we used R for resistance.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Back when I took electronics courses, we used R for resistance.
We still do; impedance is complex: Z = R + jX.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Thanks for the refresher (AC vs. DC). It's been a long time.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all,
I appologize if this is an inappropriate place to ask,
but I would appreciate if someone could help me with
the following issue.
I need to define an algebraic group (with prime
order), and define a method to transform strings of
bits, into elements of this group.
Could anyone, target me to some literature, or
programming libraries, that illustrate how to achieve
this?
Thank you in advance.
|
|
|
|