# Generating plots from the ALGORITHMS FOR OPTIMIZATION book by Kochenderfer et al

**URL:** <https://discourse.julialang.org/t/generating-plots-from-the-algorithms-for-optimization-book-by-kochenderfer-et-al/80552>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [May 5, 2022, 4:55pm UTC](https://discourse.julialang.org/t/generating-plots-from-the-algorithms-for-optimization-book-by-kochenderfer-et-al/80552 "2022-05-05T16:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![00krishna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00krishna/32/8843_2.png) [@00krishna](https://discourse.julialang.org/u/00krishna)\
**Post date:** [May 5, 2022, 4:55pm UTC](https://discourse.julialang.org/t/generating-plots-from-the-algorithms-for-optimization-book-by-kochenderfer-et-al/80552/1 "2022-05-05T16:55:59Z")

</div>

I was reading through the Algorithms for Optimization book by Kochenderfer and Wheeler. The books is replete with excellent julia code for running optimization algorithms. One challenge I have with the book is that they did not provide plotting code, to help replicate the graphs in the book. I believe that the authors are working on including plotting code for the next edition, but until then I would like to try writing some of these plots myself.

I was wondering if someone could help my to generate the following plot for gradient descent on the Rosenbrock banana function. Plotting the function is not hard, but I am not sure how to plot those isocline or level sets of the Rosenbrock function.

I have the gradient descent code and also code for the Rosenbrock function below, but could someone help to plot the isoclines here. Thanks.

Here is the plot from the book with the isoclines (p.71):  
 ![Selection_003](https://global.discourse-cdn.com/julialang/original/3X/7/2/7285a7e206c596777b322a0d08da74024ffc51d2.png)

Here is the code.

```julia
abstract type DescentMethod end
struct GradientDescent <: DescentMethod
    α
end

init!(M::GradientDescent, f, ∇f, x) = M

function step!(M::GradientDescent, f, ∇f, x)
    α, g = M.α, ∇f(x)
    return x - α*g
end

rosenbrock(x; a=1, b=5) = (a-x[1])^2 + b*(x[2] - x[1]^2)^2

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 5, 2022, 5:03pm UTC](https://discourse.julialang.org/t/generating-plots-from-the-algorithms-for-optimization-book-by-kochenderfer-et-al/80552/2 "2022-05-05T17:03:55Z")

</div>

Have you checked the GitHub repos ?  
[https://github.com/algorithmsbooks/algforopt-notebooks](https://github.com/algorithmsbooks/algforopt-notebooks)

---

<div class="post-metadata">

**Author:** ![00krishna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00krishna/32/8843_2.png) [@00krishna](https://discourse.julialang.org/u/00krishna)\
**Post date:** [May 5, 2022, 5:06pm UTC](https://discourse.julialang.org/t/generating-plots-from-the-algorithms-for-optimization-book-by-kochenderfer-et-al/80552/3 "2022-05-05T17:06:26Z")

</div>

Ohh, I did not even see these notebooks. I looked at the repo for the books, but did not catch the repo for the notebooks. Okay very good. This is even better. Thanks for pointing these out.
