{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# MA934 - Week 10 (assessed!) Problem Sheet\n", "\n", "## Deadline: 17:00 (UK time) on Friday 15 December \n", "\n", "For this assignment, you must create a new Jupyter notebook called MA934_Week10_UniID.ipynb to contain the implementations that you write. This should also be exported as a .pdf file such that all execution output (from data to plots) is visible as produced on your own machine. You can separate out individual tasks if you prefer, but the full submission should be made as a single .zip via [our website](/fac/sci/mathsys/courses/msc/ma934/resources/assessedwork/ma934declaration). The platform will not allow you to upload more than one file.\n", "\n", "A few tips:\n", "- please make sure to debug intermediate outputs as you code along. You are welcome to design smaller test cases and toy problems to verify your work (even if they are not part of the final submission).\n", "- consider possible forms of input or arguments and make sure your solution can cope with *interesting* cases.\n", "- do not forget to comment your code and use Markdown cells to explain what you are doing. A perfectly functional solution with no information about the thought process will not receive more than a subset of the points (~$70\\%$ depending on the difficulty of the problem and how transparent the algorithm flow is). \n", "- generally getting used to writing tidy solutions is good practice. Feel free to use [online resources](https://www.ibm.com/docs/en/watson-studio-local/1.2.3?topic=notebooks-markdown-jupyter-cheatsheet) for editing guidance.\n", "\n", "The problems below provide opportunities to experiment with some of the concepts we covered theoretically in the lectures, focusing on linear programming and solving ODEs." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Task 1 - Solving a simple linear programme [25 marks]\n", "\n", "Consider the following linear programme\n", "\n", "$$\\min_{\\substack{(x_1, x_2) \\in \\mathbb{R}^2} } -40\\, x_1 - 60\\, x_2$$\n", "\n", "subject to the constraints\n", "\n", "$$2\\, x_1 + x_2 \\leq 70 $$\n", "$$x_1 + 3\\, x_2 \\leq 90 $$\n", "$$ 3\\, x_1 + x_2 \\geq 46 $$\n", "$$ x_1 + 4\\, x_2 \\geq 52 $$\n", "\n", "with $x_1 \\geq 0$ and $x_2 \\geq 0$.\n", "\n", "Sketch the feasible set for this problem.\n", "\n", "Determine the coordinates of the vertices of the feasible set in $\\mathbb{R}^2$ and thereby determine the solution of the problem." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Task 2 - Dantzig simplex algorithm [35 marks]\n", "\n", "Write the above problem in standard form. Find a basic feasible vector in $\\mathbb{R}^6$ with $x_1 = 12$ and $x_2 = 10$.\n", "\n", "Write a code in Python that implements the Dantzig simplex algorithm in its simplest form.\n", "\n", "Start your code from the basic feasible vector that you found above and write down the sequence of basic feasible vectors leading to the solution you found previously." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Task 3 - ODEs, from nice to stiff [40 marks]\n", "\n", "This exercise is intended to allow a glimpse into the relative performance of different differential equation solver tupes. We can use the following problem as a setting for our exploration:\n", "\n", "$$\n", "\\frac{d u }{d t} = -\\lambda (u - \\cos(t)), \\hspace{0.1cm} \\text{ with } \\hspace{0.1cm} u(0) = 0.\n", "$$\n", "\n", "You may use your own time interval choice, but $t \\in [0,1]$ can represent a good starting point. Note that parameter $\\lambda \\in \\mathbb{R}^+$ (and its value) represents a key part of the problem. A suggested solution strategy is:\n", "- Implement the Forward Euler Method and evaluate its performance for your choice of values of $\\lambda$ of up to $100$. Powers of two are perhaps a sensible choice, but in general try 4-6 values that cover a sufficiently wide range of the interval. Remember to plot your findings (using subplots may be useful here) and comment on your results as a function of the value of $\\lambda$.\n", "- Now try an implicit scheme, such as the implicit trapezoidal method. You can think of overlaying the results when making comparative comments.\n", "- What is the effect of a more advanced method on the same problem? A Runge-Kutta $4^{\\textrm{th}}$ order accurate scheme may be a good candidate for study.\n", "- Finally, attempt to solve the problem using in-built Python solvers (non-stiff and stiff). Comment on their relative performance versus the previous implementations.\n", "\n", "**Hint:** In each of the above cases you may set a target error $\\mathcal{E}$ or any desired target behaviour, and frame your findings with respect to it. For example the choice in discrete timesteps may be guided by achieving a given accuracy level of a given time budget. Formulating this objective can represent a first paragraph of the discussion as you explore the points above, and provide a framework for benchmarking." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }