{ "cells": [ { "cell_type": "markdown", "id": "8b9b6bbc-313d-4704-8f2f-e0cc6356eb25", "metadata": {}, "source": [ "On considère la fonction $x\\rightarrow f(x)$ calculée par la fonction Scilab suivante:" ] }, { "cell_type": "code", "execution_count": 15, "id": "91307805-513a-4797-8f96-cd646b47ca00", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m" ] } ], "source": [ "function y7 = f(x)\n", " y1 = exp(x);\n", " y2 = cos(x);\n", " y3 = sin(x);\n", " y5 = y2.^3;\n", " y6 = y3.^3;\n", " y7 = y1./(y5+y6);\n", "end" ] }, { "cell_type": "markdown", "id": "a016ab07-6dbc-40fc-8279-a56b8e851634", "metadata": {}, "source": [ "On peut tracer le graphe de $f$ sur $[-\\pi/5,\\pi/2]$ avec Scilab comme ceci" ] }, { "cell_type": "code", "execution_count": 16, "id": "d4a9b739-424a-46a6-9f45-677d7283ed65", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m" ] }, { "data": { "image/svg+xml": [ "01-0.8-0.6-0.4-0.20.20.40.60.81.21.41.6241350.51.52.53.54.5" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x = linspace(-%pi/5,%pi/2,1000);\n", "plot(x,f(x))" ] }, { "cell_type": "markdown", "id": "b337b434-f310-48e0-8ef3-f021e8e06a88", "metadata": {}, "source": [ "Dans un but de comparaison, le code Scilab calculant la dérivée nous sera nécessaire:" ] }, { "cell_type": "code", "execution_count": 17, "id": "0fb79cac-9d43-4a44-b310-c5134314ed0a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m" ] } ], "source": [ "function d=fprime(x)\n", "d = (exp(x).*((cos(x).^3 + sin(x).^3) + ...\n", " 3*sin(x).*cos(x).^2-3*sin(x).^2.*cos(x)))./(cos(x).^3 + sin(x).^3).^2\n", "endfunction" ] }, { "cell_type": "markdown", "id": "a0bce235-3781-4747-9df7-1ddc35af17cf", "metadata": {}, "source": [ "On considère une approximation de la dérivée de $f$ pour $x_0\\in\\mathbb R$ par la fonction $D_1:[-\\pi/5,\\pi/2]\\times \\mathbb R\\rightarrow \\mathbb R$ définie par\n", "$$\n", "D_1(x_0,h)=\\frac{f(x_0+h)-f(x_0)}{h}\\cdot\n", "$$\n", "Pour $x_0=\\pi/4$, le programme Scilab suivant permet de vérifier que pour $h$ suffisamment petit (mais pas trop), $D_1(x_0,h)$ est une approximation d'ordre 1 de $f'(x_0)$, c'est à dire que $f'(x_0)-D_1(x_0,h)=O(h)$ (un infiniment petit d'ordre 1). " ] }, { "cell_type": "code", "execution_count": 21, "id": "d1fdebfe-d44a-4da2-a922-1e73ecaa3a43", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m" ] } ], "source": [ "x0 = %pi/4;\n", "h = 10^(-20:0.1:-1);\n", "D1 = (f(x0+h)-f(x0))./h;\n", "E1 = abs((D1-fprime(x0))/fprime(x0));" ] }, { "cell_type": "markdown", "id": "bfe13966-205f-4395-8d2c-c3a211eafd23", "metadata": {}, "source": [ "On peut tracer le graphe de l'erreur relative\n", "$$\n", "E_1(h)=\\left \\vert \\frac{f'(x_0)-D_1(x_0,h)}{f'(x_0)} \\right\\vert\n", "$$\n", "en utilisant une échelle logarithmique" ] }, { "cell_type": "code", "execution_count": 19, "id": "0087c301-797f-4fca-a7f4-e7ab20f82c13", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[4l\u001b[0m\u001b[0m\u001b[4l\u001b[0m\u001b[0m" ] }, { "data": { "image/svg+xml": [ "10-2010-1710-1410-1110-810-510-210-810-510-2101" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot(\"ll\",h,E1);\n", "isoview on" ] }, { "cell_type": "code", "execution_count": null, "id": "87b6045d-1131-4a4b-8985-edd3dae6fda8", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Scilab", "language": "scilab", "name": "scilab" }, "language_info": { "file_extension": ".sci", "help_links": [ { "text": "MetaKernel Magics", "url": "https://metakernel.readthedocs.io/en/latest/source/README.html" } ], "mimetype": "text/x-scilab", "name": "scilab", "version": "0.10.0" } }, "nbformat": 4, "nbformat_minor": 5 }