Why do i get this error when i run the code?

Hello there friends i tried to run this code in matlab r2021b
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x)*pi/180);
L=(0:20:80);
k=(0:0.5:24);
lamda=15*(12-k);
solar_altitude=asind(sind(sdelta)*sind(L)+cosd(sdelta)*cosd(L)*cosd(lamda));
but the system shows this error ...can anybody help me out.Thank you.
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches
the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in p2 (line 43)
solar_altitude=asind(sind(sdelta)*sind(L)+cosd(sdelta)*cosd(L)*cosd(lamda));

 Akzeptierte Antwort

dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x)*pi/180);
L=(0:20:80);
k=(0:0.5:24);
lamda=15*(12-k);
whos
Name Size Bytes Class Attributes L 1x5 40 double dn 1x365 2920 double k 1x49 392 double lamda 1x49 392 double sdelta 1x365 2920 double x 1x365 2920 double
solar_altitude=asind(sind(sdelta)*sind(L)+cosd(sdelta)*cosd(L)*cosd(lamda));
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
sdeleta is 1 x 365 so sind(sdelta) is also 1 x 365
L is 1 x 5 so sind(L) is 1 x 5
(1 x 365) * (1 x 5) is an invalid operation.
It looks to me as if you want a result that is per-latitude and per-day -- so a 2D result. For long term graphing purposes it is probably easiest to have connect all of the days for a particular latitude, so you probably want one line per latitude (ignoring the other factors for now), so you should arrange for sdelta to be a column.

5 Kommentare

prem kumar
prem kumar am 29 Jan. 2022
friend actually the instruction given to me is as follows:
Write a Matlab program to calculate solar altitude, at L = 0, 20, 40, 60, 80 deg for ( k = 0.5, 1, 1.5, 2, 2.5 … 24 i.e half-hour interval) for dn = 100.
Plot solar altitude, versus solar time, k at L = 0, 20, 40, 60, 80deg on a single graph.
dn = (1:1:365).';
x=(360/365*(dn+284));
sdelta=23.45*(sind(x)*pi/180);
L=(0:20:80);
k=(0:0.5:24);
lamda=15*(12-k);
whos
Name Size Bytes Class Attributes L 1x5 40 double dn 365x1 2920 double k 1x49 392 double lamda 1x49 392 double sdelta 365x1 2920 double x 365x1 2920 double
part1 = sind(sdelta)*sind(L); size(part1)
ans = 1×2
365 5
part2a = cosd(sdelta)*cosd(L); size(part2a)
ans = 1×2
365 5
part2 = part2a * cosd(lamda); size(part2)
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
solar_altitude=asind(part1 + part2);
So you now have two pieces that are 365 x 5, and you want to somehow relate them to lamda which is 1 x 49.
What size of output are you hoping for?
... Because at the moment it looks to me as if k has to do with solar time in minutes, which you would normally expect to be used to refine the day number to produce an "every 30 minutes of every day" result (one continuous vector) for each different latitude location, not a (days) by (latitudes) by (30-minute-intervals) result.
prem kumar
prem kumar am 29 Jan. 2022
but friend in the instruction they didnt specify k is in minutes or hours they only specified for lamda as where the hour angle, based on solar time k..Also its for dn=100 and they didnt specify the lattitude in the question unfortunately...i also try to search some related equation for this type of solar related problems they used lattitude at a specified location in those equations..as per the size i do not mind any output size to be honest..so it means i have to change my k value into minutes in order to get 1x365 but it is only for a day though.
dn = (1:1/24:365).';
x=(360/365*(dn+284));
sdelta=23.45*(sind(x)*pi/180);
L=(0:20:80);
k = mod(dn, 1) * 24;
lamda=15*(12-k);
whos
Name Size Bytes Class Attributes L 1x5 40 double dn 8737x1 69896 double k 8737x1 69896 double lamda 8737x1 69896 double sdelta 8737x1 69896 double x 8737x1 69896 double
part1 = sind(sdelta)*sind(L); size(part1)
ans = 1×2
8737 5
part2a = cosd(sdelta)*cosd(L); size(part2a)
ans = 1×2
8737 5
part2 = part2a .* cosd(lamda); size(part2)
ans = 1×2
8737 5
solar_altitude = asind(part1 + part2);
whos
Name Size Bytes Class Attributes L 1x5 40 double ans 1x2 16 double dn 8737x1 69896 double k 8737x1 69896 double lamda 8737x1 69896 double part1 8737x5 349480 double part2 8737x5 349480 double part2a 8737x5 349480 double sdelta 8737x1 69896 double solar_altitude 8737x5 349480 double x 8737x1 69896 double
plot(dn, solar_altitude); legend(string(L))
plot(dn(1:200), solar_altitude(1:200,:)); legend(string(L))
Perhaps the equations are not correct when dn is fractional ?
prem kumar
prem kumar am 29 Jan. 2022
but i looked at solar radiation conference book this is the same equation he used...but is it possible if to make like only for the hundredth day dn=100 instead of dn=1:200?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Solar Power finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by