Created
January 17, 2024 22:16
-
-
Save Observatorio-de-Matematica/1228409a42fdc5357ea21288be3e4e9a to your computer and use it in GitHub Desktop.
Extracted and adapted from http://www.ugr.es/~pmrivas/calculo-grado-en-informatic/derivadas-taylor-2014.wxmx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ | |
/* [ Created with wxMaxima version 22.04.0 ] */ | |
/* [wxMaxima: title start ] | |
Derivación (tema 7 de maxima.pdf) | |
[wxMaxima: title end ] */ | |
/* [wxMaxima: section start ] | |
Comando diff(f(x),x) | |
[wxMaxima: section end ] */ | |
/* [wxMaxima: comment start ] | |
Podéis hacer uso del menú: Análisis --> Derivar | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
diff(sin(x),x); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
diff(sin(x),x,14); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
diff(sin(t),x,1); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
diff(sin(t),t,1); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Para presentar la función derivada usamos el comando define: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
define(g(x),diff(sin(x),x)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
g(0); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: subsect start ] | |
Recta tangente y rectas secantes | |
[wxMaxima: subsect end ] */ | |
/* [wxMaxima: input start ] */ | |
f(x):=x^3-2*x^2-x+2; | |
define(df(x),diff(f(x),x)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
tangente(x,a):=f(a)+df(a)*(x-a); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Por ejemplo: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
tangente(x,9); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
wxdraw2d(color=blue, | |
key="funcion", | |
explicit(f(x),x,-2,3), | |
color=red, | |
key="tangente", | |
explicit(tangente(x,1),x,-2,3), | |
point_type=filled_circle, | |
color=dark-blue, | |
points([[1,f(1)]]), | |
grid=true); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Y ahora las rectas secantes. | |
En primer lugar, definimos la recta que pasa por | |
los puntos (a,b) y (c,d): | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
recta(x,a,b,c,d):=x*(b-d)/(a-c)+(a*d-c*b)/(a-c); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Y ahora dibujamos en un mismo gráfico la función f, la recta tangente en el punto | |
(1,f(1)) y la recta secante que pasa por (1,f(1)) y por (1+0.6,f(1+0.6)). | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
wxdraw2d( | |
point_type=filled_circle, | |
color=dark-blue, | |
points([[1,f(1)],[2,f(2)]]), | |
point_type=filled_circle, | |
color=blue, | |
key="funcion", | |
explicit(f(x),x,-2,3), | |
color=red, | |
key="tangente", | |
explicit(tangente(x,1),x,-2,3), | |
color=dark-green, | |
key="secante", | |
explicit(recta(x,1,f(1),2,f(2)),x,-2,3), | |
grid=true); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Con una animación veremos cómo van aproximándose | |
las rectas secantes a la recta tangente. | |
Hacemos esto con incrementos decrecientes: h=1,0.9,0.8,0.7,...0.1. | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
incrementos:0.1*reverse(makelist(i,i,1,10)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
with_slider( | |
n,incrementos, | |
[f(x),tangente(x,1),recta(x,1,f(1),1+n,f(1+n))], | |
[x,-2,3]); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: section start ] | |
Máximos y mínimos relativos | |
[wxMaxima: section end ] */ | |
/* [wxMaxima: comment start ] | |
Vamos a calcular los extremos relativos de la siguiente función: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
remfunction(all); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
f(x):=2*x^4+4*x; | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
wxplot2d([f(x)], [x,-2,1])$ | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Calculamos, en primer lugar, los | |
puntos críticos de la función: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
define(df1(x),diff(f(x),x)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
puntos:solve(df1(x)=0,x); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
puntos[3]; | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
a:float(rhs(%)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Vamos a decidir si el punto crítico es de extremo o no | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
df1(-1); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
df1(0); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
O podemos utilizar el test de la derivada segunda: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
define(df2(x),diff(f(x),x,2)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
df2(a); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Por tanto, en el punto x=a se alcanza un mínimo relativo. | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: comment start ] | |
¿Hay más extremos relativos? No | |
¿Se alcanza el mínimo absoluto? Sí | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: section start ] | |
Hacer los ejemplos 7.4, 7.5, 7.6 y | |
7.7 del | |
tema 7 de maxima.pdf. | |
[wxMaxima: section end ] */ | |
/* [wxMaxima: section start ] | |
Polinomio de Taylor | |
(Volvemos al capítulo 10) | |
[wxMaxima: section end ] */ | |
/* [wxMaxima: comment start ] | |
Acabamos de ver cómo la recta tangente a una función en un punto aproxima localmente | |
a dicha función en ese punto. Es decir, que si sustituimos una función por su recta tangente en | |
un punto, estamos cometiendo un error como se puede ver. En efecto, si dibujamos en una misma | |
gráfica la función f (x) = cos(x) y su recta tangente en cero, | |
obtenemos: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
f(x):=cos(x); | |
define(df(x),diff(f(x),x)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
p(x):=f(0)+df(0)*x; | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
wxplot2d([f(x),p(x)], [x,-3,3], [y,-2,2])$ | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
wxplot2d([f(x),p(x)],[x,-3,3],[y,-2,2]); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
En cuanto nos alejamos un poco del punto de tangencia | |
(en este caso el 0), la función coseno y su tangente no se | |
parecen en nada. La forma de mejorar la aproximación | |
será aumentar el grado del polinomio que usamos, y la | |
cuestión es, fijado un grado n, qué polinomio de grado | |
menor o igual al fijado es el que más se parece a la función. | |
El criterio con el que elegiremos el polinomio será | |
hacer coincidir las sucesivas derivadas, esto es, el polinomio | |
de Taylor de orden n de una función f en un punto | |
a. | |
Definimos el polinomio de Taylor. | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: comment start ] | |
El programa tiene una orden que permite calcular directamente el polinomio de Taylor centrado | |
taylor en un punto a. Se trata del comando taylor | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
taylor(f(x),x,0,5); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
taylor(sin(x),x,0,8); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Si hacemos un gráfico conjunto: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
wxplot2d([f(x),taylor(f(x),x,0,100)], | |
[x,-60,60],[y,-2,2]); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Vamos a aumentar el grado del polinomio de Taylor: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
wxplot2d([f(x),taylor(f(x),x,0,16)], | |
[x,-4,4],[y,-2,2]); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Y ahora aumentamos el rango de la variable x: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
wxplot2d([f(x),taylor(f(x),x,0,8)], | |
[x,-40,40],[y,-2,2]); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
LLegamos a la conclusión de que taylor aproxima | |
mejor a medida que el orden n sea | |
mayor. Pero lo hace siempre localmente; es decir, | |
cuando nos alejamos del punto a protagonista, las dos | |
gráficas se separan. | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
kill(all); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: subsect start ] | |
Ejemplo: Dibujar, en un mismo gráfico, | |
f(x)=sin(x)+cos(x), y los cuatro primeros | |
polinomios de taylor en cero. | |
[wxMaxima: subsect end ] */ | |
/* [wxMaxima: input start ] */ | |
remfunction(f); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
f(x):=sin(x)+cos(x); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
define(t1(x),taylor(f(x),x,0,1)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
define(t2(x),taylor(f(x),x,0,2)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
define(t3(x),taylor(f(x),x,0,3)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
define(t4(x),taylor(f(x),x,0,4)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: input start ] */ | |
wxdraw2d(color=blue,key="funcion", | |
explicit(f(x),x,-%pi/2,%pi/2), | |
color=red, explicit(t1(x),x,-%pi/2,%pi/2), | |
color=yellow, explicit(t2(x),x,-%pi/2,%pi/2), | |
color=green, explicit(t3(x),x,-%pi/2,%pi/2), | |
color=purple,explicit(t4(x),x,-%pi/2,%pi/2)); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: comment start ] | |
Mejor, hacemos una animación: | |
[wxMaxima: comment end ] */ | |
/* [wxMaxima: input start ] */ | |
with_slider(n,makelist(i,i,1,20), | |
[f(x),taylor(f(x),x,0,n)],[x,-10,10],[y,-3,3]); | |
/* [wxMaxima: input end ] */ | |
/* [wxMaxima: section start ] | |
Ejercicios: (página 168 del capítulo 10) | |
[wxMaxima: section end ] */ | |
/* [wxMaxima: subsect start ] | |
Ejercicio 10.6. | |
Estudia los extremos relativos del | |
polinomio de Taylor de | |
orden 5 centrado en el origen de la función | |
f(x)= cos(x)+e^x. | |
[wxMaxima: subsect end ] */ | |
/* Old versions of Maxima abort on loading files that end in a comment. */ | |
"Created with wxMaxima 22.04.0"$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment