When a solar ship is navigating in the ocean, the swaying motion of a photovoltaic panel will affect the output power of the photovoltaic (PV) power generation system more frequently and violently. In addition to considering multiple climatic factors, this paper also adopts a ship swaying motion and radiation level of sunlight to establish a suitable calculation model for the output power of photovoltaic systems, which are rarely considered at the same time in previous studies, and also to make ultrashort-term power predictions. Furthermore, this paper proposes a multilayer heterogeneous particle swarm optimization (PSO) algorithm to design the weights and thresholds of a long short-term memory (LSTM) neural network to improve the accuracy of forecasting the changes of a photovoltaic panel’s angle, which is used for accurate power output prediction for the purpose of power planning. The case analysis shows the effectiveness of the algorithm, which provides a more reliable method for designing a power prediction system.