Introduction to optimization with applications in astronomy and astrophysics