Bob's pick this week is sun_position.m by Vincent Roy.
Here at MathWorks headquarters in Natick, MA we are entering the dog days of Summer. Like many others to help stay cool during the day I minimize unwanted solar heating through windows with shades and blinds. Of course that conserves energy which also saves money!
From a technical aspect you can calculate the position of the Sun. Given a place and time sun_position does the math for you. For example, where is my Noon Sun today?
here.longitude = -71.34993; %deg here.latitude = 42.30013; %deg here.altitude = 55; %m noonToday = datenum('2010-07-16 12:00'); sun_position(noonToday,here)
ans =
zenith: 63.368
azimuth: 84.585
Wikepedia helped get my head around what zenith and azimuth mean.
Thanks to Vincent for making that so easy for me to use. His submission also has a lot of good feedback from others. I appreciate submissions like this where people collaboratively make good work even better as the "updates" section makes clear. Keep up the great work, everyone!
Do you use solar calculations? Tell us about it here.
Get
the MATLAB code
Published with MATLAB® 7.10


The picture you have of zenith is correct, it is always 90 degrees above your horizon (straight up, opposite of nadir), the angle the Sun makes at it’s highest point (not always at noon) is called usually called the elevation angle.
Also, the highest point of the Sun’s elevation is called the transit time, and is not always at noon. See my web link (a java applet) that shows the actual elevation values at the Sun Transit time.
Example: for your location specified, for July 17, the Sun Transit time is 12:51:35 (local), with an elevation of 68.829 degrees.
I used this to calculate whether to buy real estate 20m left or right, since there will be higher buildings next to ours at some point in future. Calculating sun position helped to determine at what time in the morning we will get sun.
Your example is misleading. You are not calculating the position of the Sun for your noon. Look at the angles.
The error is that the time is not specified in your particular time zone.
Ted, thanks for the information. Great point that noon is not necessarily highest.
Joachim, very cool application – thanks for sharing!
Petter, so whose Noon is 12:00 at my location?
I meant with respect to time zones. I noticed that the sun wasn’t at its highest point at 12:00. I assumed to was a time zone problem, since the time zone isn’t specified anywhere.
Rookie mistake: local time threw me. Eastern time zone is 5 hours from UTC, and we’re on Daylight Savings Time now. So Noon on my watch really means 12:00 UTC +(5-1=)4 hours.
>> transitTime = datenum('2010-07-16 12:51:35')+4/24;>> p = sun_position(transitTime,here)
p =
zenith: 20.9967
azimuth: 180.0608
>> 90-p.zenith
ans =
69.0033
Bob,
It looks like you took the Transit time for the 17th (from my example above) and used it to calculate the zenith angle for the 16th. The transit time changes a little bit everyday. Your azimuth shows this too – it’s a little off of 180 degrees.
Using the date of 7/17 in your example:
>> transitTime = datenum('2010-07-17 12:51:35')+4/24; >> p = sun_position(transitTime,here) p = zenith: 21.1656445823035 azimuth: 180.004396015302 >> 90 - p.zenith ans = 68.8343554176965Which is much closer. I only have the transit time to the second precision, there are probably more decimal places in the time, which may give us closer answers. By the way, my Java Applet (referenced in my link) uses Jean Meeus’ algorithms as well, from his Astronomical Algorithms book. He has many test cases in the book that you can try too. Nice job!
Ted, good catch. So I nailed the time but was a full day off. (blush) If it was a snake, it would have bit me! LOL