This book teaches the users on how to construct a library of routines to simulate scattering and diffraction by almost any kind of samples. The main goal of this book is to break down the huge barrier of difficulties faced by beginners from many fields (Engineering, Physics, Chemistry, Biology, Medicine, Material Science, etc.) in using X-rays as an analytical tool in their research. Besides fundamental concepts, MatLab routines are provided, showing how to test and implement the concepts. The major difficult in analysing materials by X-ray techniques is that it strongly depends on simulation software. This book teaches the users on how to construct a library of routines to simulate scattering and diffraction by almost any kind of samples. It provides to a young student the knowledge that would take more than 20 years to acquire by working on X-rays and relying on the available textbooks. The scientific productivity worldwide is growing at a breakneck pace, demanding ever more dynamic approaches and synergies between different fields of knowledge. To master the fundamentals of X-ray physics means the opportunity of working at an infiniteness of fields, studying systems where the organizational understanding of matter at the atomic scale is necessary. Since the discovery of X radiation, its usage as investigative tool has always been under fast expansion afforded by instrumental advances and computational resources. Developments in medical and technological fields have, as one of the master girders, the feasibility of structural analysis offered by X-rays. One of the major difficulties faced by beginners in using this fantastic tool lies in the analysis of experimental data. There are only few cases where it is possible to extract structural information directly from experiments. In most cases, structure models and simulation of radiation-matter interaction processes are essential. The advent of intense radiation sources and rapid development of nanotechnology constantly creates challenges that seek solutions beyond those offered by standard X-ray techniques. Preparing new researchers for this scenario of rapid and drastic changes requires more than just teaching theories of physical phenomena. It also requires teaching of how to implement them in a simple and efficient manner. In this book, fundamental concepts in applied X-ray physics are demonstrated through available computer simulation tools. Using MatLab, more than eighty routines are developed for solving the proposed exercises, most of which can be directly used in experimental data analysis. Therefore, besides X-ray physics, this book offers a practical programming course in modern high-level language, with plenty of graphic and mathematical tools.