manual wolfram mathematica v8 by @jmarquezc

25
Póngase en contacto con el administrador del sitio o propietario del documento Scribe: @jmarquezc Informes:

Upload: jmarquezc

Post on 21-Apr-2015

6.698 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Manual Wolfram Mathematica v8 by @jmarquezc

Póngase en contacto con el administrador del sitio o propietario del documento

Scribe: @jmarquezc Informes:

Page 2: Manual Wolfram Mathematica v8 by @jmarquezc

Cálculo Diferencial e Integral aplicado en Mathematica 8

Contenido:

Derivando e integrando en Mathematica

Usando los puntos críticos de una función para graficarla

Sólidos de revolución

Graficando funciones y ecuaciones en tres dimensiones

Potenciales Electrostáticos en dos y tres dimensiones

Derivando e integrando en Mathematica

En esta sección se muestran brevemente los comandos para derivar e integrar en Mathematica. Estos comandos también serán usados en las siguientes

secciones.

Primero nos aseguramos que los nombres "x" y "u" no contiene ningún valor

In[1]:=

Para derivar una función se utiliza el comando D[ ]:

In[2]:=

Out[2]=

A continuación se deriva usando el símbolo de derivada de la paleta

In[3]:=

Out[3]=

El comando D[ ] asume que todas las letras que no correspondan a la variable de derivación representan constantes, como en una derivada parcial

In[4]:=

Out[4]=

Page 3: Manual Wolfram Mathematica v8 by @jmarquezc

En cambio, el comando Dt asume que todas las letras son funciones de la variable de derivación, como en una derivada total

In[5]:=

Out[5]=

Usando la paleta podemos calcular integrales indefinidas (antiderivadas)

In[6]:=

Out[6]=

También se pueden calcular integrales definidas (áreas bajo curvas)

In[7]:=

Out[7]=

El número resultado del cálculo anterior es el área bajo la curva desde 1.5 hasta 3.5

Podemos ver dibujada esta área usando el comando FilledPlot

Primero es necesario cargar la libreria con el comando FilledPlot

In[8]:=

Aquí graficamos la función junto con el área bajo la curva. El dibujo se guarda con el nombre "fp"

In[10]:=

Out[10]=

Aquí mejoramos el aspecto del dibujo:

In[11]:=

Page 4: Manual Wolfram Mathematica v8 by @jmarquezc

Out[12]=

Usando los puntos críticos de una función

para graficarla

¿Que vamos a hacer en esta práctica?

En esta práctica de Mathematica aprenderás algunos comandos relacionados con la definición, graficación y derivación de funciones, así como la

solución de ecuaciones, y el uso de toda esta información para encontrar los rangos de valores en los ejes coordenados que permiten realizar la mejor

gráfica de una función.

Definiendo y graficando una función.

Primero nos aseguramos que no haya información previa ni valor alguno metido en el nombre "f", que es el que vamos a utilizar para nuestra función.

También vamos a limpiar los nombres "x", "dibujo1", "dibujo2" y "derivada" que utilizaremos en esta práctica.

In[1]:=

ES MUY IMPORTANTE QUE COPIES EXACTAMENTE, INCLUYENDO EL GUION LARGO _ SOLO EN EL LADO IZQUIERDO DEL

PRIMER COMANDO ASI COMO LOS DOS PUNTOS Y EL PUNTO Y COMA EN SU LUGAR:

Page 5: Manual Wolfram Mathematica v8 by @jmarquezc

In[2]:=

Out[3]=

lo que hicimos en el primer renglón fue definir la función "f", mientras que en el segundo renglón el comando plot sirve para graficarla. Nota que se

especificó que se graficara en el dominio de 0 a 10 dentro del comando plot.

Averiguando si hay un mejor dominio para graficar la función

En la gráfica que se obtuvo, la función parece continuar creciendo y creciendo conforme los valores de "x" aumentan. ¿Será esta una descripción

adecuada de esta función?. Para averiguarlo, podemos calcular los valores críticos de la función, que son los valores de "x" en los cuales la derivada de

la función vale cero. Los valores críticos son máximos, mínimos o puntos de inflexión de la función.

Primero obtenemos la derivada de la función mediante el comando D[ ], escribe:

In[4]:=

Out[4]=

este resultado a quedado guardado en la memoria de la computadora bajo el nombre "derivada". Nota que la definición de la función está en memoria

bajo el nombre "f" y por eso pudimos utilizarla en el comando D[ ].

Ahora vamos a averiguar los valores de "x" para los cuales la derivada es cero mediante el comando Solve[ ].

ES IMPORTANTE USAR EN ESTE COMANDO DOS SIGNOS DE IGUAL "==".

In[5]:=

Out[5]=

Para graficar de -1 a 61 escribe:

In[6]:=

Page 6: Manual Wolfram Mathematica v8 by @jmarquezc

Out[6]=

Podemos notar que la función tiene más estructura de la que se veia en el inciso anterior. Sin embargo, esta gráfica aún se puede mejorar, como se

muestra en el siguiente inciso.

Mejorando visualmente el dominio y el rango de la función.

La gráfica del inciso anterior ya incluye los valores críticos en los cuales la derivada es cero. Pero también es necesario saber como se comporta la

gráfica antes y después de esos valores, así que grafiquemos desde un número anterior al -1 hasta otro posterior al 61. Si escogemos graficar del -2 al 62

es poco probable que obtengamos más información, así que grafiquemos desde el -51 (restándole 50 al primer valor crítico) hasta el 111 (sumándole 50

al segundo valor crítico):

In[7]:=

Out[7]=

En esta gráfica ya se alcanza a observar que el valor crítico -1 corresponde a un mínimo local de la función, mientras que el valor crítico 61 corresponde

a un máximo local. También observa que Mathematica graficó una línea casi vertical en x=30. Esta línea es incorrecta, ya que no forma parte de la

función, porque la función tiene una asíntota vertical en x=30 (revisa la definición de la función en el primer inciso).

Observa que Mathematica decidió que el eje "Y" debe ir de -400 a 400. Quizás se obtenga una gráfica que resalte más la forma de la función si

graficamos en un rango más pequeño, por ejemplo, le podemos indicar a Mathematica que grafique con un rango en "Y" desde -250 a 100 mediante la

opción PlotRange adentro del comando Plot:

In[8]:=

Page 7: Manual Wolfram Mathematica v8 by @jmarquezc

Out[8]=

Eliminando la línea casi vertical de la gráfica

Al dibujar una gráfica, Mathematica va uniendo con líneas a los puntos (x,f[x]). Por ello, al unir un punto a la izquierda del x=30 con otro punto a la

derecha del x=30, Mathematica produce la línea casi vertical que cruza en x=30. De hecho, la función tiene una asíntota en x=30 (ve la definición de la

función en el primer inciso). Podríamos quedarnos con la gráfica del inciso anterior, recordando que la línea casi vertical no es parte de la función, más

bien es aproximadamente la asíntota.

Por otro lado, si deseamos eliminar esta línea del dibujo para quedarnos unicamente con el dibujo correcto de la función, podemos realizar dos dibujos,

uno de -51 hasta 30, al cual llamaremos dibujo1, y otro de 30 hasta 111, al cual llamaremos dibujo2, y luego le indicamos a Mathematica que los

muestre juntos:

In[9]:=

Page 8: Manual Wolfram Mathematica v8 by @jmarquezc

Out[11]=

Como observaste obtuvimos tres gráficas, las cuales son dibujo1, dibujo2 y por último las dos juntas.

Ejercicio

¿Para que valores de x tiene asíntotas verticales la función? (Es decir, para que valores de x se vuelve cero el denominador de la fracción)

Encuentra la derivada de la función con respecto a x. ¿Para qué valores de x se vuelve cero la derivada?

Realiza una gráfica de la función. Escoge el dominio (valores en x) y el rango (valores en y) para que la gráfica muestre claramente todas las

características de la función (asíntotas, máximos, mínimos, curvatura, etc.)

Realiza una gráfica como la anterior pero que las asíntotas no sean dibujadas.

Sólidos de revolución

Primero nos aseguramos que los nombres "x" y "u" no contiene ningún valor

In[1]:=

Esta es una función que usaremos como ejemplo:

In[2]:=

Out[3]=

Page 9: Manual Wolfram Mathematica v8 by @jmarquezc

Primero cargamos la librería de Mathematica con los comandos para dibujar superficies de revolución:

In[4]:=

Esta es la superficie generada cuando hacemos girar la función alrededor del eje y:

In[6]:=

Out[6]=

Esta es la superficie generada cuando hacemos girar la función alrededor del eje x:

In[7]:=

Out[7]=

Ejemplo de un sólido de revolución: Fabricando una pieza de ajedrez

Supón que estamos fabricando una pieza de ajedrez. Una de las piezas se puede generar al hacer girar la siguiente función alrededor del eje x:

Page 10: Manual Wolfram Mathematica v8 by @jmarquezc

Primero define la función seccionada usando el comando "which"

In[8]:=

Out[8]=

Aquí puedes ver el dibujo de la función seccionada que creamos

In[9]:=

Out[9]=

Esta es la pieza de ajedrez generada cuando la función gira alrededor del eje "x":

In[10]:=

Page 11: Manual Wolfram Mathematica v8 by @jmarquezc

Out[10]=

Supón que necesitamos conocer la cantidad de material necesaria para construir la pieza de ajedrez. Esa cantidad de material es el volumen, que se puede

calcular con las siguientes integrales (revisa "sólidos de revolución" en tu libro de cálculo):

In[11]:=

Out[11]=

Si todas las unidades de la pieza de ajedrez están en centímetros, entonces el volumen calculado está en centímetros cúbicos.

Ejercicio: La botella de refresco

Ejercicio:

a) Crea la fórmula de una función seccionada tal que cuando sea girada alrededor del eje x se genere la figura de una botella de refresco, como se

muestra la figura más abajo. Tu botella de refresco debe ser de 24 centímetros de largo

b) Dibuja la botella usando el comando SurfaceOfRevolution

c) Calcula el volumen de la botella en centímetros cúbicos

d) Convierte el volumen de la botella a mililitros

Page 12: Manual Wolfram Mathematica v8 by @jmarquezc

Graficando funciones y ecuaciones en tres

dimensiones

Graficando funciones que dependen de dos variables

Una función "z" que depende de dos variables "x","y", es una fórmula que permite calcular "z" si se conocen "x" y "y". Es decir, "z" está despejada.

Primero nos aseguramos que los nombres "x", "y", "z" no tengan nada

In[1]:=

In[2]:=

Out[2]=

Otra forma de visualizar la función es obtener el diagrama de contorno, que es como un mapa topográfico, lo más obscuro está más abajo:

In[3]:=

Page 13: Manual Wolfram Mathematica v8 by @jmarquezc

Out[3]=

Graficando ecuaciones de tres variables

Una ecuación de tres variables, "x", "y", "z", es una relación en la cual la variable "z" no está necesariamente despejada,y a diferencia de la función,

pueden haber diferentes valores de "z" para el mismo (x,y)

Es necesario ejecutar el siguiente comando para cargar en la memoria de la computadora los comandos para graficar ecuaciones con tres variables. Ten

cuidado de usar las comillas correctas

In[4]:=

In[6]:=

Page 14: Manual Wolfram Mathematica v8 by @jmarquezc

Out[6]=

Hay varias opciones que permiten cambiar el aspecto del dibujo:

In[7]:=

Out[7]=

Aquí está el dibujo de otra cuádrica:

In[8]:=

Page 15: Manual Wolfram Mathematica v8 by @jmarquezc

Out[8]=

Electric Potentials in two and three

dimensions

Mathematica Project

Author: José Luis Gómez-Muñoz

[email protected]

What are you going to do?

You will use Mathematica in order to plot the potential and electric fields produced by parallel wires with electrical charge (functions of two variables)

and by spherical electrical charges (functions of three variables). Copy the examples and verify that you obtain the same results, and then solve the

exercises at the end of this document. You can work with Mathematica at the computer laboratory

Electric Potential of a wire with electrical charge

The figure shows a section of a large wire with electrical charge. We will plot the electric potential, the equipotential curves and the electric field in a

plane perpendicular to the wire (some equipotential curves in the perpendicular plane are shown)

Page 16: Manual Wolfram Mathematica v8 by @jmarquezc

The electric potential V in volts of a large wire of charge is given by:

If the wire has a radius and the potential must be continuous, the potential becomes:

Here (x,y) are the plane coordinates in meters, λ is the linear density of charge in Coulomb/meter and is the "vacuum permittivity" constant:

For this exercise we will use a linear density of charge of

And a wire radius of

The potential for this exercise is:

In[1]:=

Out[3]=

We will plot the potential for -0.05<x<0.05 and -0.05<y<0.05 meters. The surface is constant inside the wire, and a decreasing function outside:

In[4]:=

Page 17: Manual Wolfram Mathematica v8 by @jmarquezc

Out[4]=

A level curve of a function is made of points with the same value of the function. A plot with several level curves for different values is called a contour

plot, and it is like a topographic map of the surface. In Physics, the level lines of an electric potential are called "equipotential lines". Notice that the plot

is stored in the variable cp1:

In[5]:=

Out[5]=

The gradient of a function V is the vector function given by

This vector is a function of x and y,and in each point (x,y) it points toward the direction of maximum increase of the function.In Physics,the electric field

E is a vector given by:

and it gives the force that a charge of 1 coulomb would experience in each point (x,y). The next command stores the plot of the gradient of our potential

in the variable pg1:

In[6]:=

Page 18: Manual Wolfram Mathematica v8 by @jmarquezc

Out[8]=

Now we show together the level curves and the gradient field. Notice that the gradient arrows point in the direction of higher increase of the function,

and they are perpendicular to the level curves.

In[9]:=

Out[9]=

Electric Potential of two parallel wires with charge of different sign

The figure shows two parallel wires with linear charge densities:

Page 19: Manual Wolfram Mathematica v8 by @jmarquezc

They are at a distance of 0.10 meters from each other. We will plot the electric potential, the equipotential curves and the electric field in a plane

perpendicular to the wires (some equipotential curves in the perpendicular plane are shown)

We define the potential using the function v[x,y] of the previous exercise. Notice that the positive wire intersects the plane at (0.05,0) and the negative

wire intersects the plane at (-0.05,0):

In[10]:=

Out[10]=

We plot the potential for -0.05<x<0.05 and -0.05<y<0.05 meters:

In[11]:=

Out[11]=

In this exercise, the level curves (or equipotential curves) are circles with different center and different radius:

In[12]:=

Page 20: Manual Wolfram Mathematica v8 by @jmarquezc

Out[12]=

The gradient arrows make "lines of force" which go from one wire to the other.

In[13]:=

Out[15]=

The gradient vector is always perpendicular to the level curve, and it points in the direction of higher increase of the function:

In[16]:=

Page 21: Manual Wolfram Mathematica v8 by @jmarquezc

Out[16]=

A function of three variables: Electric Potential in space

We will study the potential of two spherical charges of different sign, each one with a charge:

Each sphere has a radius of:

and they are separated 0.08 meters from each other. This configuration is called "electric dipole":

Potential of one spherical charge:

If the sphere has a radius and the potential must be continuous then the potential becomes:

Therefore the potential for a single sphere of this exercise is:

In[17]:=

Page 22: Manual Wolfram Mathematica v8 by @jmarquezc

Out[19]=

Potential for the two spherical charges separated 0.08 meters:

In[20]:=

Out[20]=

A level SURFACE of a function is made of points with the same value of the function. A plot with several level surfaces for different values is called a

contour plot. In Physics, the contour surfaces of an electric potential are called "equipotential surfaces":

In[21]:=

Out[23]=

Improved equipotential surfaces (level surfaces):

In[24]:=

Page 23: Manual Wolfram Mathematica v8 by @jmarquezc

Out[24]=

The gradient of a function V is the vector function given by:

This vector is a function of x, y, and z, and in each point (x,y,z) it points toward the direction of maximum increase of the function. In Physics, the

electric field E is a vector given by:

and it gives the force that a charge of 1 coulomb would experience in each point (x,y,z). In the next graph you can see a plot of the gradient of the

potential v2p. Can you see the arrows leaving one charge and pointing to the other?:

In[25]:=

Page 24: Manual Wolfram Mathematica v8 by @jmarquezc

Out[27]=

In the next array of graphics, the first column corresponds to the function of two variables and the second column to the function of three variables.

Notice that we cannot plot the 4D hypersurface corresponding to the function of three variables.

In[28]:=

Out[29]=

Exercise (Parallel Wires)

Create a new function v4[x,y] for the potential of four paralell wires:

two negative at (0.05, 0) and (-0.05, 0)

Page 25: Manual Wolfram Mathematica v8 by @jmarquezc

and two positive at (0, 0.05) and (0, -0.05)

Then make the Plot3D, ContourPlot and PlotGradientField plots of this potential.

Exercise (Spheres)

Create a new function v4p[x,y,z] for the potential of four spheres of charge:

two negative at (0.05, 0, 0) and ( -0.05, 0, 0)

and two positive at (0, 0, 0.05) and (0, 0, -0.05).

Then make the ContourPlot3D and PlotGradientField3D plots of this potential.