# How to use a function with array output for each value in a different array?

3 ビュー (過去 30 日間)
Esi Balaban 2021 年 10 月 6 日
コメント済み: Esi Balaban 2021 年 10 月 6 日
Hello,
I am trying to calculate how much of the sun's energy is collected by the earth every year in a particular location.
I have already calculated how much energy is collected for every daylight hour in one day. To do this, I calculated the zenith angle for the sun at every daylight hour:
phi = 43 % longitude
delta = 7 % solar declination
w = [80 , 60 , 50 , 30 , 20 , 5] % sun angles at every daylight hour
zenith = acosd((cosd(phi)*cosd(delta)*cosd(w))+(sind(phi)*sind(delta))); % zenith angles
This gives me 6 zenith angles for each angle input. So I have the zenith angles for a day.
I now want to do this for every day of the year.
Each day, the solar declination (delta) changes. I can calculate these values, delta ends up being an array with 365 values.
Because delta and w have different array sizes, I haven't been able to use this function for these two arrays at once and I do not know how to do them separately. Ideally, I would want a matrix with each day's zenith angles on each row of the matrix.
How do I do this?

サインインしてコメントする。

### 採用された回答

Stephen 2021 年 10 月 6 日
"Ideally, I would want a matrix with each day's zenith angles on each row of the matrix."
That is easy, just make sure that DELTA and W are vectors with the appropriate orientations. Note also that I used TIMES (i.e. element-wise multiplication) and not MTIMES (i.e. matrix multiplication) like you used.
phi = 43; % longitude
delta = (0:0.1:20).'; % solar declination for lots of days
w = [80,60,50,30,20,5]; % sun angles at every daylight hour
zenith = acosd((cosd(phi).*cosd(delta).*cosd(w))+(sind(phi).*sind(delta)))
zenith = 201×6
82.7038 68.5508 61.9589 50.7007 46.5874 43.2333 82.6351 68.4775 61.8816 50.6126 46.4935 43.1337 82.5663 68.4043 61.8044 50.5245 46.3996 43.0342 82.4976 68.3311 61.7272 50.4365 46.3058 42.9346 82.4289 68.2579 61.6501 50.3485 46.2120 42.8350 82.3602 68.1848 61.5730 50.2605 46.1182 42.7355 82.2915 68.1117 61.4959 50.1725 46.0244 42.6359 82.2228 68.0386 61.4189 50.0846 45.9307 42.5364 82.1542 67.9656 61.3419 49.9967 45.8369 42.4368 82.0855 67.8926 61.2650 49.9089 45.7432 42.3373
##### 1 件のコメント表示非表示 なし
Esi Balaban 2021 年 10 月 6 日
Thank you so much! That makes a lot of sense, will make sure to check orientations next time...

サインインしてコメントする。

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by