Click to See Complete Forum and Search --> : network therom
azzi
May 22nd, 2008, 11:02 AM
hi
i have to create a program that does ac thevenins using vb but dont know how to use complex numbers or change from rectangular to polar
jemidiah
May 22nd, 2008, 07:52 PM
What does "ac thevenins" mean? If you need a tutorial in complex numbers from the ground up, this probably isn't the place because they're a huge topic. Maybe you could ask a teacher or friend in more advanced math... unless you have more specific questions for us.
azzi
May 22nd, 2008, 08:01 PM
i know how to do it jsut not using visual basic:( and because its ma uni project a kant ask ( a kan ask but they kant help without deducting marks)
for example if a give you 3 values
Z1=34+j8
z2=32+j90
i have to convert it to polar form so my answer is x to the angle of y
if anyone can help me it would be great if not oh well
jemidiah
May 23rd, 2008, 06:23 AM
How much VB do you know? I'm sure quite a few of us could give you the solution but it's much better to lead you to it instead.
azzi
May 23rd, 2008, 10:23 AM
i know a fair bit of vb and have made various other vb programs like a timer and calculater
once i see the code i will know where i went wrong
NickThissen
May 23rd, 2008, 11:03 AM
If you know how to do it mathematically (by hand), I'm sure it's not too hard to translate that into VB code?
For example, to convert a complex number in the form of z = x + jy to polar coordinates, you first need to find the length of the vector:
r = sqrt( x2 + y2 )
Then you need to find the angle:
tanθ = b/a --> θ = arctan(b/a)
The polar form is now:
z = r * ejθ = r ( cosθ + j sinθ )
These are all functions present in VB (probably Math.Arctan for example).
With numbers:
Convert z = 4 + 3i to polar form:
z = sqrt( 42 + 32 ) exp( j * arctan(3/4) )
Not that hard, right? Is this what you want to do?
EDIT
By "AC Thevenins" the topicstarter probably means using Thevenins theorem to model the input/output characteristics of any linear electrical network (with an AC source) to merely one source and one resistor.
azzi
May 23rd, 2008, 04:52 PM
yeah thats it thanks
so say a have 3 ac values
z1= 120+2j
z2= 31+2j
z3= 70+31j
v1= 31
would a have to state as a integer or anything
thanks in advance
NickThissen
May 23rd, 2008, 05:24 PM
You'll have to tell us more about what you want to do exactly...
Do you simply want to display a number like z = x + jy in the polar form: z = r ejθ, or do you want to do calculations with them?
If you simply want to display it in polar form you can probably use something along the lines of:
Dim z(1) As Double
z(0) = 120 'Real part
z(1) = 2 'Imaginery part
txtPolar.Text = Math.Sqrt( z(0)^2 + z(1)^2 ).ToString & "exp( j " & Math.Arctan( z(1) / z(0) ) & " )"
This simply uses a Double z with as an array with two entries. z(0) is the real part and z(1) is the imaginery part.
So z = x + jy becomes:
z(0) = x
z(1) = y
And z = 91 + 3j becomes:
z(0) = 91
z(1) = 3
azzi
May 23rd, 2008, 05:44 PM
yeah
basically what should happen is the user enters 3 values (z1 z2 z3) and v and my program should work out the thevenins voltage and the thevenins impedance and then showing the answer in rectanguar form aswell as polar form
jemidiah
May 24th, 2008, 07:32 PM
Could you just use InputBox and MsgBox for input and output? The rest you should be able to do based on Nick's example (though he wrote it in .NET instead of in VB6).
azzi
May 24th, 2008, 07:43 PM
yeah i can am just confused whats the difference with .net and vb ?
what would i have to change from nicks code
thanks
jemidiah
May 25th, 2008, 01:37 AM
You'd have to use Atn() instead of Math.Arctan, Str() instead of the .ToString method, and Sqr() [no t] instead of Math.Sqrt. Also, you should probably note that the tangent function isn't truly invertible--for example, -1-i and +1+i have different angles, but Atn(-1/-1)=Atn(1/1) = pi/4. You should account for this with appropriate if checks, if it matters in your case.
NickThissen
May 25th, 2008, 03:32 AM
One problem with my method is that arctan(1/1) will not show as pi/4, but as 0.785398...
You could 'hardcode' a few of these 'neat angles' so your program recognizes them.
azzi
May 25th, 2008, 04:22 PM
nick i will be using simple numbers so a wont have to hardcode anything a just have to show it works
does anyone have any vb6 samples of the program cos am still not sure
thanks all for your help
NickThissen
May 26th, 2008, 03:42 AM
The VB.NET code I posted above would probably be something like this in VB6:
Dim z(1) As Double
z(0) = 120 'Real part
z(1) = 2 'Imaginery part
txtPolar.Text = Str(Sqr( z(0)^2 + z(1)^2 )) & "exp( j " & Str(Atn( z(1) / z(0))) & " )"
azzi
May 26th, 2008, 02:56 PM
nick what am getting confused at is what do i state z0 = as the number will change from time to time so do i state z0 = x or something along those lines ?
NickThissen
May 26th, 2008, 03:18 PM
In my code I am just assigning some random imaginery number to z. How you want to do it in your code depends completely on how the user inputs the number. For example you could use two inputboxes:
z(0) = Dbl( InputBox("Enter the real part:") )
z(1) = Dbl( InputBox("Enter the imaginery part:") )
(I believe 'Dbl' is used to convert to double, right?)
(You could also use just one inputbox and store it to a string, then use string functions to retrieve the real and imaginery parts)
azzi
May 26th, 2008, 05:36 PM
i have attached what i have done so far how would you code it for the ac?
thanks
jemidiah
May 27th, 2008, 01:27 AM
Assuming you want to do what you mentioned above with coordinate conversions, you have more than enough information to do code that yourself....
azzi
May 27th, 2008, 07:12 AM
i have tried the above code but i am still getting error messages
azzi
May 28th, 2008, 12:25 PM
has any one had any luck with the code am desparate now :lol: :blush:
NickThissen
May 28th, 2008, 12:47 PM
If you could just explain to us exactly what you want to do instead of let us guess you might get better help!
You are only telling us glimpses of what you need... You need some way to convert a cartesian complex number to a complex number in polar coordinates. I have gave you the exact code for that. How and why does the user need this program? How is the user going to input the number in the first place, how are you going to use the convert number afterwards, etc... etc..?
azzi
May 28th, 2008, 01:10 PM
sorry if i have not been clear
i have attached the forms of what i have done so far on the 26th may
the user will enter 3 values as shown on my ac form and then click calculate the program should then work out the thevenins resistance and thevenisn voltage in both polar and in rectangular form
i have doen the dc version so if you look at that its simiar to that the answer should be displayed on screen
NickThissen
May 28th, 2008, 01:44 PM
I'm sorry I dont have VB6 installed here so I can't check out your forms.
If you have the DC version you should also be able to work out the AC version... Have you managed to get the AC version in 'rectangular' form? If so, you can easily use the code I gave you to convert it to polar form...
jemidiah
May 28th, 2008, 05:08 PM
I did look at the code, but I still don't really know what you want.... However from the code you've got, you really really should have enough information to do this. Sorry, but I'm not coding it for you. If you have a line of code that gives an error, I'm sure people would be happy to explain it and help fix it, but you haven't given us that.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.