This book provides readers with the skills they need to write computer codes that simulate convection, internal gravity waves, and magnetic field generation in the interiors and atmospheres of rotating planets and stars. Using a teaching method perfected in the classroom, the book begins by offering a step-by-step guide on how to design codes for simulating nonlinear time-dependent thermal convection in a 2D box using Fourier expansions in the horizontal direction and finite differences in the vertical direction. It then describes how to implement more efficient a nd accurate numerical methods and more realistic geometries in two and three dimensions. The third part of the book demonstrates how to incorporate more sophisticated physics, including the effects of magnetic field, density stratification, and rotation. The book features numerous exercises throughout, and is an ideal textbook for students and an essential resource for researchers. It explains how to create codes that simulate the internal dynamics of planets and stars, and builds on basic concepts and simple methods. The book shows how to improve the efficiency and accuracy of the numerical methods. It considers more relevant geometries and boundary conditions.