Matrix dimensions must agree error problem

Hello everyone, I'm trying to plot this Code but it gives me an error: Matrix dimensions must agree
How can I sove the problem?
number_of_the_yearly_day = 1:1:365;
declination=23.45*sin((2*pi*(number_of_the_yearly_day-80))/(365));
latitude=31.963158;
Zenith_angle=latitude-declination;
tilt_angle=Zenith_angle;
altitude=1-Zenith_angle;
T=0:1:24;
w=15*(12-T);
X=asind(sin(declination).*sin(latitude)+cos(latitude).*cos(declination).*cos(w));
Y=acosd(sin(altitude)*sin(latitude)-sin(declination)/(cos(altitude)*cos(latitude)));
plot (x,Y)

Réponses (1)

James Tursa
James Tursa le 2 Août 2021
Use element-wise division with the dot:
Y=acosd(sin(altitude)*sin(latitude)-sin(declination)./(cos(altitude)*cos(latitude)));

5 commentaires

clc
clear all
number_of_the_yearly_day = 1:1:365; %n
T=1:1:24;
declination=23.45*sin((2*pi*(number_of_the_yearly_day-80))/(365));%𝛿
latitude=31.963158; %∅
Zenith_angle=latitude-declination; %𝜃𝑧
tilt_angle=Zenith_angle;%𝛽
altitude=1-Zenith_angle;
w=15*(12-T);
X=asind(sin(declination).*sin(latitude)+cos(latitude).*cos(declination).*cos(w));
Y=acosd(sin(altitude).*sin(latitude)-sin(declination)./(cos(altitude).*cos(latitude)));
plot (X,Y)
like this? it still gives me an error
ibrahim alzoubi
ibrahim alzoubi le 2 Août 2021
Matrix dimensions must agree. ERORR
James Tursa
James Tursa le 2 Août 2021
I just noticed the w. This is a different size than declination. What were you expecting the outcome of cos(declination).*cos(w) to be given the different sizes involved? Are you looking to generate a 2D matrix of results, or ...?
ibrahim alzoubi
ibrahim alzoubi le 2 Août 2021
I'm looking to gerate 2D matrix where w represents hours (24 hour)
James Tursa
James Tursa le 2 Août 2021
Modifié(e) : James Tursa le 2 Août 2021
Try turning the w part into a column vector and then use implicit expansion. E.g., cos(w'). Note that this results in X being a 2D matrix and Y being a 1D vector. Does that do what you want?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by