I'm afraid I can't tell what you're trying to do with your code, but it sure looks far too simple. I suspect you need to start from a rigorous framework so that you know what you're doing. If I were to do this, these are the parameters by which I would define the problem, I think:
1. The earth's axis of rotation relative to the sun (this can be assumed constant at 23.5 degrees)
2. The angle of your house's location relative to the north pole - at the north pole would be 0, pi/2 is on the equator, pi is south pole.
3. The angle you are facing at this position on the Earth's surface. Say you have a south-facing window.
domain variables (parameters):
1. The current time within the day (0 through 2*pi, where one period is one sidereal day, which is 23 hours, 56 minutes and 4 seconds). 0 would be midnight with the time within the year equal to 0.
2. The current time within the year. Equal to 0 in the dead of winter (if you're in the Northern hemisphere). Ok, so January 1 isn't the solstice, but you can worry about fudge factors like that later.
range variables (functions to calculate):
1. The theta spherical coordinate of the sun in the sky from the chosen vantage point (constant #3)
2. The phi spherical coordinate of the sun in the sky from the chosen vantage point (constant #3)
Just set it up this way and it should conceptually fall into place, I think. You can check your solution from known results, for instance at the North or South poles, the periodic variations due to domain variable 1, the time within the day, should fall to 0, at 23.5 degrees (the arctic circle) the magnitude of the daily variation should be just large enough in magnitude so that in the middle of summer the sun falls exactly to the horizon (spherical coordinate phi is pi/2) at midnight and in the middle of winter for it to just reach the horizon at noon, and at the lines of tropics, for the phi coordinate to be able to reach 0 or pi only on the solstices.