{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Analytical test case # 1\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, we consider a simple optimization problem to illustrate\nalgorithms interfaces and :class:`.MDOFunction`.\n\n## Imports\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import annotations\n\nfrom numpy import cos\nfrom numpy import exp\nfrom numpy import ones\nfrom numpy import sin\nfrom scipy import optimize\n\nfrom gemseo import configure_logger\nfrom gemseo.core.mdofunctions.mdo_function import MDOFunction\n\nconfigure_logger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define the objective function\nWe define the objective function $f(x)=\\sin(x)-\\exp(x)$\nusing an :class:`.MDOFunction` defined by the sum of :class:`.MDOFunction` s.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "f_1 = MDOFunction(sin, name=\"f_1\", jac=cos, expr=\"sin(x)\")\nf_2 = MDOFunction(exp, name=\"f_2\", jac=exp, expr=\"exp(x)\")\nobjective = f_1 - f_2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. seealso::\n\n The following operators are implemented: $+$, $-$\n and $*$. The minus operator is also defined.\n\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "objective" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Minimize the objective function\nWe want to minimize this objective function over $[-2,2]$,\nstarting from 1.\nWe use scipy.optimize for illustration.\n\n
:class:`.MDOFunction` objects are callable like a Python function.