help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Different Behaviour matlab and octave


From: lrohr
Subject: Different Behaviour matlab and octave
Date: Tue, 17 Nov 2009 03:21:04 -0800 (PST)

Hi there,
I'm using octave and matlab and try my code to be compatible ... 
Actually I wrote a small Sunposition calculater, which calculates the suns
altitude and azimuth seen from a place on earth. So this is my code :

function [solarAltitude,solarAzimuth] = sunposition (longitude,latitude)
        days            = (1:365);
        minutes_a_day   = (1:1440)';
        D  = days(ones(1440,1),days)-1;
        M  = minutes_a_day(:,ones(365,1))-1;
        DM = D+(M./1440);
        % Position of the Earth, in rad, around the sun
        EP = 2*pi*(DM/365);
        % Sun Declination
        SD = 0.0068906 - 0.40589
*cos(EP+0.15882)-0.0068330*cos(2*EP+0.08901179)-0.0030788*cos(3*EP+1.8361);
                
        % hour Angle
        HA = (12-(M/60))*0.26180;
        
        % solar Altitude
        SALT =
asin(cos(deg2rad(latitude))*(cos(HA).*cos(SD))+sin(deg2rad(latitude))*sin(SD));
        
        % solar Azimuth
        SAZI =
acos((sin(SALT)*sin(deg2rad(latitude))-sin(SD))./(cos(SALT)*cos(deg2rad(latitude))));
        
        solarAltitude            = rad2deg(SALT);
        solarAzimuth(1:720,:)    = 180 - rad2deg(SAZI(1:720,:));
        solarAzimuth(721:1440,:) = 180 + rad2deg(SAZI(721:1440,:));
    
    
end

Just to explaine the first hard to understand lines : I used a Matrix with
(minutes_a_day,days_a_year) size so it is (1440,365). The DM matrix starts
with 0 and is added 1/1440 (one minute) per row down and 1 (day) per column
to the right, so the value is corresponding to the time left behind in this
year ... 

The longitude isn't needed yet (will implement the mean time later ... ) so
to start the only thing you got to do is call :

[alt,azi] = sunposition(0,49);

where 49 is the 49° latitude. In the matlab/octave file I used the deg2rad
and rad2deg functions which are simply

function d=rad2deg(rad)
    d = (rad/(2*pi))*360;
end


function r=deg2rad(deg)
    r = (deg/360)*2*pi;
end


The altitude is the same in both matlab/octave and correct.
So octave behaves just like I wanted to, the altitude is correct and the
azimuth.
But matlabs fails with the azimuth and I don't know why. 

I put in the screen shot of the plots of azimuth. octave does it right
matlab doesn't.

Does anyone find the reason why ?
Here the octave plot :
http://old.nabble.com/file/p26388251/octave_plot.png 

and the matlab plot :
http://old.nabble.com/file/p26388251/matlab_plot.png 
-- 
View this message in context: 
http://old.nabble.com/Different-Behaviour-matlab-and-octave-tp26388251p26388251.html
Sent from the Octave - General mailing list archive at Nabble.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]