@@ -799,36 +799,6 @@ Aim for clarity, not efficiency.
|
799 | 799 | ```{exercise-end} |
800 | 800 | ``` |
801 | 801 | |
802 | | - |
803 | | -```{exercise-start} |
804 | | -:label: oop_ex2 |
805 | | -``` |
806 | | - |
807 | | -In an {ref}`earlier exercise <pyess_ex2>`, you wrote a function for evaluating polynomials. |
808 | | - |
809 | | -This exercise is an extension, where the task is to build a simple class called `Polynomial` for representing and manipulating polynomial functions such as |
810 | | - |
811 | | -```{math} |
812 | | -:label: polynom |
813 | | - |
814 | | -p(x) = a_0 + a_1 x + a_2 x^2 + \cdots a_N x^N = \sum_{n=0}^N a_n x^n |
815 | | - \qquad (x \in \mathbb{R}) |
816 | | -``` |
817 | | - |
818 | | -The instance data for the class `Polynomial` will be the coefficients (in the case of {eq}`polynom`, the numbers $a_0, \ldots, a_N$). |
819 | | - |
820 | | -Provide methods that |
821 | | - |
822 | | -1. Evaluate the polynomial {eq}`polynom`, returning $p(x)$ for any $x$. |
823 | | -1. Differentiate the polynomial, replacing the original coefficients with those of its derivative $p'$. |
824 | | - |
825 | | -Avoid using any `import` statements. |
826 | | - |
827 | | -```{exercise-end} |
828 | | -``` |
829 | | - |
830 | | -## Solutions |
831 | | - |
832 | 802 | ```{solution-start} oop_ex1 |
833 | 803 | :class: dropdown |
834 | 804 | ``` |
@@ -865,6 +835,34 @@ print(F(0.5))
|
865 | 835 | ```{solution-end} |
866 | 836 | ``` |
867 | 837 | |
| 838 | + |
| 839 | +```{exercise-start} |
| 840 | +:label: oop_ex2 |
| 841 | +``` |
| 842 | + |
| 843 | +In an {ref}`earlier exercise <pyess_ex2>`, you wrote a function for evaluating polynomials. |
| 844 | + |
| 845 | +This exercise is an extension, where the task is to build a simple class called `Polynomial` for representing and manipulating polynomial functions such as |
| 846 | + |
| 847 | +```{math} |
| 848 | +:label: polynom |
| 849 | + |
| 850 | +p(x) = a_0 + a_1 x + a_2 x^2 + \cdots a_N x^N = \sum_{n=0}^N a_n x^n |
| 851 | + \qquad (x \in \mathbb{R}) |
| 852 | +``` |
| 853 | + |
| 854 | +The instance data for the class `Polynomial` will be the coefficients (in the case of {eq}`polynom`, the numbers $a_0, \ldots, a_N$). |
| 855 | + |
| 856 | +Provide methods that |
| 857 | + |
| 858 | +1. Evaluate the polynomial {eq}`polynom`, returning $p(x)$ for any $x$. |
| 859 | +1. Differentiate the polynomial, replacing the original coefficients with those of its derivative $p'$. |
| 860 | + |
| 861 | +Avoid using any `import` statements. |
| 862 | + |
| 863 | +```{exercise-end} |
| 864 | +``` |
| 865 | + |
868 | 866 | ```{solution-start} oop_ex2 |
869 | 867 | :class: dropdown |
870 | 868 | ``` |
|