This Matlab code simulates ship rolling behavior in irregular waves and calculates the probability of capsizing for different sea states. It first generates irregular wave time series data and calculates wave parameters. It then uses the Runge-Kutta method to solve the ship rolling differential equation to obtain roll angle time series. Probability distributions and CDFs are plotted for wave amplitude, heeling moment, roll angle and righting moment. The code also calculates the probability of various failure events and compares the capsizing probability over different sea states.