Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with math question

Status
Not open for further replies.

vbdrk

Programmer
Aug 10, 2002
14
US
Hi, I am trying to make a solar position calculator based on the details from the National Oceanic & Atmospheric Administration (NOAA). There are also internet based calculators and they use javascript to function. Anyhow, I have a one page sheet of the equation that I am trying to make a VB6 calculator to obtain sunrise, sunset, and solar noon results and have a few snags. For instance, one line I am having trouble to use in VB is the following:
cos(Phi )=sin(lat)*Math.sin(declin)+cos(lat)*cos(declin)*cos(ha)
where I get an error "Function call on left hand side of assignment must return a variable or object". I have the code original equation I can post if anybody wants to try and help me :)
Thanks,
vbdrk
 
Cos(phi) is a function call - it is attempting to evaluate the cosine of the variable phi - you can't assign an arbritrary value to it!

If the equation that you've given is correct, and you need to evaluate phi, then calculate the intermediate value first:

x = sin(lat)*Math.sin(declin)+cos(lat)*cos(declin)*cos(ha)
phi = acos(x)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
John, Thanks for the quick response. Do you mind if I show you the equation here so you can see what I have to work with. I will give you the link and then you can see if what I have to work with, will work. First I obtained the PDF from the NOAA and it was confusing a bit so I looked and found a more clarified version of it. I will show you both (or anyone else interested).
The above link has the original PDF (its the first item under Calculations. The next link is a 1 page text file that makes it a bit clearer.
Does it look like it will work? It seems like a few things are confusing me like "Math.sin" and I named my variable for Phi to SolarZenithAngle and the term "Theta" to SolarAzimuth. Anyway, I appreciate any comments.
Thanks,
vbdrk
 
The 2 articles appear to me to be equivalent - they both look like they will work. I had assumed the Math.sin was a private function that you had generated, but it isn't. Just replace it with sin.

You'll need to do a similar intermediate for solar azimuth, but it all looks straightforward. Don't forget that the VB trig functions all work in radians, not degrees, so you'll need to convert as required. (1 radian = 180/pi degrees in case you forgot).

For ArcSin and ArcCos you'll need to look up the Derived Trigonometric functions in VBHelp - you'll find them called Inverse Sine and Inverse Cosine

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I think this will work for you. Let me know if it works or not. I love this stuff:

Code:
Option Explicit
Dim Pi As Single

Private Sub Form_Load()
Pi = 3.14159265358979
End Sub

Private Function MyCos(D As Single)
MyCos = Cos((D * (Pi / 180)))
End Function

Private Function MySin(E As Single)
MySin = Sin((E * (Pi / 180)))
End Function

Private Function InvCos(X As Single)
InvCos = (Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)) / (Pi / 180)
End Function

Private Function SolarZenithAngle(Lat As Single, Declin As Single, Ha As Single)
On Error GoTo errorHandler
SolarZenithAngle = InvCos(MySin(Lat) * MySin(Declin) + MyCos(Lat) * MyCos(Declin) * MyCos(Ha))
Exit Function

errorHandler:
SolarZenithAngle = "-ERR-"
End Function

***You can't change your past, but you can change your future***
 
johnwm: Thanks for checking the links and letting me know whats up. I'm not the most advanced when it comes to the math involved here but doing it is the best way to learn :) I will keep working at it but I have to admit, I found a class module that does just what I need. I still am going to work with this equation just for learning to see if I can get it to accurately display the answers I need. I appreciate your helpfulness.
Thanks,
vbdrk
 
Wraygun: Thanks for elaborating on the extra math in the functions you provided to get me through this. I guess it would be easier if I understood some of the math involved to obtain the answers with a calculator. It almost seems like surveyor math. Anyhow, like I told johnwm, I have found a class module that does all this and maybe more, but I still want to make this work for the extra knowledge I will gain. You love this stuff :) Well, I like it alot but once I understand it, I am sure to love it too. Could you explain why everyone uses a different amount of decimal places in their use of Pi and how much difference it makes in lets say minutes in the end result? So this is what they mean when they speak of rocket scince :)
Thanks,
vbdrk
 
Going from 4 dp to 5 dp in the value of Pi will make substantially less than a second difference in a 24hr calculation. There is no point in specifying Pi to more than 6 dp if you're using a Single datatype, as calculation rounding errors are likely to exceed any further precision.

BTW this is only ordinary secondary school trigonometry. In the UK many 15/16 yr olds would tackle this stuff.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
vbdrk:

No problem at all. Let us know if we can help further. :)


Have a good one.

Harold

***You can't change your past, but you can change your future***
 
johmwm,

Also true for the US (16:16 year olds would do this), but by the time many (most?) of them finish 'secondary school', they are again not familiar with it.



MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 

That was certainly true for me. I was in my late 20's and had to dig out the old books. US




***You can't change your past, but you can change your future***
 
Blushing...Thanks guys. You know how when you were in school and thought, "I'll never need to remember this stuff as I won't ever use it in real life", well now more than ever do I wish I was a math expert! Without giving away my age (old), I just recently started programming in the last few years so I have had alot of learning to do :) The last time I did any programming, which I must admit helped, was on a Commodore 64. Good old Basic. I guess when I got out of school all I did was mechanical stuff most of my life, with the 2 exceptions being a bartender and a chef early on. Not much trig there :) Always had an interest in computers though and have built and repaired many in the last several years. Anyhow, I appreciate your support and kind words.
Thanks,
vbdrk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top