GitHub

@@ -18,7 +18,7 @@ single: Python; Object-Oriented Programming

18181919

## Overview

202021-

In an earlier lecture, we learned some foundations of object-oriented programming.

21+

In an {doc}`earlier lecture <oop_intro>`, we learned some foundations of object-oriented programming.

22222323

The objectives of this lecture are

2424

@@ -72,7 +72,7 @@ Let's cover general OOP concepts before we specialize to Python.

7272

single: Object-Oriented Programming; Key Concepts

7373

```

747475-

As discussed an earlier lecture, in the OOP paradigm, data and functions are **bundled together** into "objects".

75+

As discussed an {doc}`earlier lecture <oop_intro>`, in the OOP paradigm, data and functions are **bundled together** into "objects".

76767777

An example is a Python list, which not only stores data but also knows how to sort itself, etc.

7878

@@ -302,7 +302,7 @@ There are no examples of the last rule in the preceding code but we will see som

302302303303

In this section, we look at some more formal details related to classes and `self`

304304305-

* You might wish to skip to the next section the first time you read this lecture.

305+

{doc}`the next section <oop_solow_growth>`* You might wish to skip to the first time you read this lecture.

306306

* You can return to these details after you've familiarized yourself with more examples.

307307308308

Methods actually live inside a class object formed when the interpreter reads

@@ -368,15 +368,15 @@ Here

368368

* $n$ is the population growth rate

369369

* $\delta$ is the depreciation rate

370370371-

A **steady state** of the model is a $k$ that solves `solow_lom` when $k_{t+1} = k_t = k$.

371+

A **steady state** of the model is a $k$ that solves {doc}`solow_lom <solow_lom>` when $k_{t+1} = k_t = k$.

372372373373

Here's a class that implements this model.

374374375375

Some points of interest in the code are

376376377-

* An instance maintains a record of its current capital stock in the variable `self.k`.

378-

* The `h` method implements the right-hand side of `solow_lom`.

379-

* The `update` method uses `h` to update capital as per `solow_lom`.

377+

{doc}`solow_lom <solow_lom>`{doc}`solow_lom <solow_lom>`* An instance maintains a record of its current capital stock in the variable `self.k`.

378+

* The `h` method implements the right-hand side of .

379+

* The `update` method uses `h` to update capital as per .

380380

* Notice how inside `update` the reference to the local method `h` is `self.h`.

381381382382

The methods `steady_state` and `generate_sequence` are fairly self-explanatory

@@ -666,7 +666,7 @@ ax.set_ylabel('$x_t$', fontsize=16)

666666

plt.show()

667667

```

668668669-

On the horizontal axis is the parameter $r$ in `quadmap2`.

669+

On the horizontal axis is the parameter $r$ in {doc}`quadmap2 <quadmap2>`.

670670671671

The vertical axis is the state space $[0, 1]$.

672672

@@ -780,7 +780,7 @@ Aim for clarity, not efficiency.

780780781781

### Exercise 2

782782783-

In an earlier exercise, you wrote a function for evaluating polynomials.

783+

In an {doc}`earlier exercise <pyess_ex2>`, you wrote a function for evaluating polynomials.

784784785785

This exercise is an extension, where the task is to build a simple class called `Polynomial` for representing and manipulating polynomial functions such as

786786

@@ -791,11 +791,11 @@ p(x) = a_0 + a_1 x + a_2 x^2 + \cdots a_N x^N = \sum_{n=0}^N a_n x^n

791791

\qquad (x \in \mathbb{R})

792792

```

793793794-

The instance data for the class `Polynomial` will be the coefficients (in the case of `polynom`, the numbers $a_0, \ldots, a_N$).

794+

The instance data for the class `Polynomial` will be the coefficients (in the case of {doc}`polynom <polynom>`, the numbers $a_0, \ldots, a_N$).

795795796796

Provide methods that

797797798-

1. Evaluate the polynomial `polynom`, returning $p(x)$ for any $x$.

798+

{doc}`polynom <polynom>`1. Evaluate the polynomial , returning $p(x)$ for any $x$.

799799

1. Differentiate the polynomial, replacing the original coefficients with those of its derivative $p'$.

800800801801

Avoid using any `import` statements.

Read the original on github.com ↗