Array division giving incorrect answer?
Show older comments
Hello, I am working on a code that reads in an excel sheet and creates arrays from the columns. These arrays are then manipulated together as seen below.
if true
filename = 'Book1.xlsx';
n = xlsread(filename,'B:B');
hour_angle = xlsread(filename,'D:D');
lat = 40;
slope = 32;
azimuth_angle=0;
declination=23.45*sind(360/365*(284+n));
cos_angleofincidence=sind(declination).*sind(lat).*cosd(slope)-sind(declination).*cosd(lat).*sind(slope).*cosd(azimuth_angle)+cosd(declination).*cosd(lat).*cosd(slope).*cosd(hour_angle)+cosd(declination).*sind(lat).*sind(slope).*cosd(azimuth_angle).*cosd(hour_angle)+cosd(declination).*sind(slope).*sind(hour_angle);
cos_zenithangle=cosd(lat).*cosd(declination).*cosd(hour_angle)+sind(lat).*sind(declination);
Rb=cos_angleofincidence./cos_zenithangle
end
(To simplify my explanation, I am just going to use the last number in the array as an example)
From cos_angleofincidence, the last number in the array is given as -0.9655. The last number in cos_zenithangle comes out to be -0.9567. As I understand it, Rb should have them dividing as an array because of the "./", so it should be -.9655/-.9567. The answer I get instead is 0.0010.
If I leave all lines in the code the same, but change Rb to look at only that last couple as below:
if true
% code
Rb=cos_angleofincidence(8760)./cos_zenithangle(8760)
end
I instead get an answer of Rb = 1.0092 for said couple (which is the answer I am looking for).
Can anyone please explain what is going on? I really don't understand what is changing between the two. I would really appreciate any help you guys can give.
Thank you so much!
Caitlin
2 Comments
Image Analyst
on 22 Nov 2015
Are you sure you're not overlooking a 1e3 in the display somewhere? Please attach book1.xlsx so we can run your code.
ck120812
on 22 Nov 2015
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!