{ "cells": [ { "cell_type": "markdown", "id": "4fd62ed1", "metadata": { "editable": true, "slideshow": { "slide_type": "slide" } }, "source": [ "The following code defines a solver for quadratic equation." ] }, { "cell_type": "code", "execution_count": null, "id": "ed8fbf08", "metadata": { "editable": true, "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "quad_roots(a, b, c) := block(\n", " [Delta, x1, x2],\n", " /* Compute the discriminant */\n", " Delta: b^2 - 4*a*c,\n", " /* Compute the roots using the quadratic formula */\n", " x1: (-b + sqrt(Delta)) / (2*a),\n", " x2: (-b - sqrt(Delta)) / (2*a),\n", " /* Return the roots as a list */\n", " return([x1, x2])\n", ")$" ] }, { "cell_type": "markdown", "id": "a6c56fdb", "metadata": {}, "source": [ "The roots of $x^2-3x+2=0$ are:" ] }, { "cell_type": "code", "execution_count": null, "id": "b1484a4e", "metadata": {}, "outputs": [], "source": [ "quad_roots(1, -3, 2);" ] }, { "cell_type": "markdown", "id": "a6e11044", "metadata": {}, "source": [ "The roots of $ax^2-bx+c=0$ are:" ] }, { "cell_type": "code", "execution_count": null, "id": "272ff689", "metadata": { "editable": true, "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "quad_roots(a, b, c);" ] } ], "metadata": { "kernelspec": { "display_name": "Maxima", "language": "maxima", "name": "maxima" } }, "nbformat": 4, "nbformat_minor": 5 }