The water hammer (WH) phenomenon is one of the most dangerous phenomena in hydraulic systems, especially pipelines, gates, and locks on these lines. There are many analytical solutions to deal with the WH phenomenon, including the treatment of friction losses, but most solutions use linear arithmetic operations, which depart from the actual situation of the WH phenomenon. Also, the methods currently used are most challenging and complex and give imprecise results to treat the mentioned phenomenon. In order to reach a state closer to the situation of losses and stability of the hydraulic system that is close to the actual state, basic partial differential equations were used, taking into account the losses generated in the hydraulic system through mathematical conversion. MATLAB was used to program and solve equations, find mathematical results, draw system diagrams, and simulate a WH wave. Various parameters were investigated to show the stability behavior of the hydraulic system by using state-space Method. So, the effect of the pressure, flow rate, diameter, and fluid type were investigated to calculate the stability of the hydraulic system. The results evaluated showed that the system’s oscillation is less at lower pressure, and the stability period is longer than that at high pressures. In addition, the system needs a longer time to stabilize at the low flow speed due to pressure waves that occur. The stability of the system affected by the WH was examined, and the effect of fluid-specific variables such as velocity, pressure, and type of fluid in addition to the diameter of the pipe and their impact on WH stability was found. The behavior of stability at the WH is nonlinear, and that is why the linear and nonlinear parts of the governing equations of the structure are used to find system through the state-space method through programming and simulation of MATLAB program.