Known longitude and latitude, calculate the sun and moon’s rising and setting times and dusk time based on matlab

?About the author: A Matlab simulation developer who loves scientific research. He cultivates his mind and improves his technology simultaneously. For cooperation on MATLAB projects, please send a private message.

Personal homepage: Matlab Research Studio

Personal credo: Investigate things to gain knowledge.

For more complete Matlab code and simulation customization content, click

Intelligent optimization algorithm Neural network prediction Radar communication Wireless sensor Power system

Signal processing Image processing Path planning Cellular automaton Drone

Content introduction

With the continuous development of science and technology, we can now obtain the longitude and latitude of any place on the earth through a variety of methods. This provides convenience for us to understand local astronomical phenomena. Among them, it is very useful to calculate the rise and set times of the sun and moon and the twilight time. In this article, we will explore how to calculate these times based on known latitude and longitude.

First, let’s understand some basic concepts in astronomy. When observing astronomical phenomena on the earth, we usually use the horizon coordinate system to describe the position of celestial bodies. In this coordinate system, the position of a celestial body is determined by two parameters: azimuth and altitude. Azimuth is the angle measured counterclockwise from true north and ranges from 0 to 360 degrees. Altitude angle is the angle between a celestial body and the ground plane, ranging from 0 to 90 degrees.

The sun and moon rise and set times and twilight time are related to azimuth and altitude angles. When the altitude angle of the sun or moon reaches 0 degrees, they rise or set. Twilight time refers to the period of time between when the sun goes down and when it becomes completely dark. During this time, there is still some residual light in the sky, but it is enough for us to see objects around us clearly.

Now, let’s see how to calculate these times. We can use astronomical algorithms to calculate the altitude and azimuth of the Sun and Moon. These algorithms calculate based on the position and time of celestial objects. For the Sun, we can use the heliocentric ecliptic coordinate system to calculate its position. For the moon, we can use the lunar ecliptic coordinate system to calculate its position.

Once we have calculated the altitude and azimuth of the Sun and Moon, we can calculate their rise and set times using the following formulas:

cos(H) = (sin(-0.8333) – sin(φ) × sin(δ)) / (cos(φ) × cos(δ))

Among them, H is the altitude angle of the celestial body, φ is the latitude of the observation location, and δ is the declination of the celestial body. When cos(H) is greater than 1, the sun or moon never rises or sets. When cos(H) is less than -1, the sun or moon is always below the horizon. In this case, we can calculate their rise and fall times using the following formula:

t = acos(-tan(φ) × tan(δ)) / 15

Among them, t is time, and the unit is hours. When cos(H) is between -1 and 1, we can calculate the rise and fall times using the following formula:

t = (H ± L) / 15 + RA – 6.6974

Among them, L is the geographical longitude and RA is the right ascension of the celestial body. When the celestial body is the sun, we need to change 6.6974 to -12.

Calculating twilight time is also easy. We can use the following formula:

t = (cos(-6°) – sin(φ) × sin(δ)) / (cos(φ) × cos(δ))

Among them, t is time, and the unit is hours. When t is negative, the sun has not set yet. When t is a positive number, the sun has set.

In the modern world, we have various software and tools available to us to calculate the sun and moon rise and set times and twilight times. For example, astronomy enthusiasts can use free software such as Stellarium to observe celestial objects. For professional astronomers and astronomical researchers, they usually use more precise tools to perform calculations.

In conclusion, it is very useful to calculate the rise and set times of the sun and moon, as well as the twilight time. They help us understand local astronomical phenomena and plan our activities. By using astronomical algorithms and modern tools, we can easily calculate these times and enjoy a wonderful astronomical journey.

Part of the code

%% Clear environment variables</code><code>warning off % Close alarm information</code><code>close all % Close open figure window</code><code>clear % Clear variables</code><code>clc % clear command line</code><code>?</code><code>%% import data</code><code>res = xlsread('dataset.xlsx');</code><code>?</code><code>%% divide the training set and test set</code><code>temp = randperm(357);</code><code>?</code><code>P_train = res(temp(1: 240), 1: 12)';</code><code>T_train = res(temp(1: 240), 13)';</code><code>M = size(P_train , 2);</code><code>?</code><code>P_test = res(temp(241: end), 1: 12)';</code><code>T_test = res(temp(241 : end), 13)';</code><code>N = size(P_test, 2);</code><code>?</code><code>%% data normalization</code><code>[p_train, ps_input] = mapminmax(P_train, 0, 1);</code><code>p_test = mapminmax('apply', P_test, ps_input);</code><code>t_train = ind2vec(T_train) ;</code><code>t_test = ind2vec(T_test );

Operation results

References

[1] SUN Nan, Sun Nan, ZHU Kai-jia, et al. Establishment and solution of the “moon on willow branches, people meet after dusk” model [C]//China Society of Industrial and Applied Mathematics. Chinese Society of Industrial and Applied Mathematics, 2015.

[2] CHEN Chao, Chen Chao, ZHANG Tian-lin, et al. Mathematical models of astronomical phenomena in classical poetry [C]//China Society of Industrial and Applied Mathematics. Chinese Society of Industrial and Applied Mathematics, 2015.

[3] Shen Shuyun, Wang Li, Guo Sanmin, et al. Research on sun shadow positioning based on geometric methods [J]. Journal of Hebei Northern University: Natural Science Edition, 2017, 33(1):7.DOI:10.3969/j.issn .1673-1492.2017.01.005.

Some theories are quoted from online literature. If there is any infringement, please contact the blogger to delete it
Follow me to receive massive matlab e-books and mathematical modeling materials

Complete code and data acquisition via private message and real customization of paper data simulation

1 Improvements and applications of various intelligent optimization algorithms
Production scheduling, economic scheduling, assembly line scheduling, charging optimization, workshop scheduling, departure optimization, reservoir scheduling, three-dimensional packing, logistics location selection, cargo space optimization, bus scheduling optimization, charging pile layout optimization, workshop layout optimization, Container ship stowage optimization, water pump combination optimization, medical resource allocation optimization, facility layout optimization, visible area base station and drone site selection optimization
2 Machine learning and deep learning
Convolutional neural network (CNN), LSTM, support vector machine (SVM), least squares support vector machine (LSSVM), extreme learning machine (ELM), kernel extreme learning machine (KELM), BP, RBF, width Learning, DBN, RF, RBF, DELM, XGBOOST, TCN realize wind power prediction, photovoltaic prediction, battery life prediction, radiation source identification, traffic flow prediction, load prediction, stock price prediction, PM2.5 concentration prediction, battery health status prediction, water body Optical parameter inversion, NLOS signal identification, accurate subway parking prediction, transformer fault diagnosis
2. Image processing
Image recognition, image segmentation, image detection, image hiding, image registration, image splicing, image fusion, image enhancement, image compressed sensing
3 Path planning
Traveling salesman problem (TSP), vehicle routing problem (VRP, MVRP, CVRP, VRPTW, etc.), UAV three-dimensional path planning, UAV collaboration, UAV formation, robot path planning, raster map path planning , multimodal transportation problems, vehicle collaborative UAV path planning, antenna linear array distribution optimization, workshop layout optimization
4 UAV applications
UAV path planning, UAV control, UAV formation, UAV collaboration, UAV task allocation, and online optimization of UAV safe communication trajectories
5 Wireless sensor positioning and layout
Sensor deployment optimization, communication protocol optimization, routing optimization, target positioning optimization, Dv-Hop positioning optimization, Leach protocol optimization, WSN coverage optimization, multicast optimization, RSSI positioning optimization
6 Signal processing
Signal recognition, signal encryption, signal denoising, signal enhancement, radar signal processing, signal watermark embedding and extraction, EMG signal, EEG signal, signal timing optimization
7 Power system aspects
Microgrid optimization, reactive power optimization, distribution network reconstruction, energy storage configuration
8 Cellular Automata
Traffic flow, crowd evacuation, virus spread, crystal growth
9 Radar aspect
Kalman filter tracking, track correlation, track fusion