Main Content

La traducción de esta página aún no se ha actualizado a la versión más reciente. Haga clic aquí para ver la última versión en inglés.

Aprender cálculo usando Symbolic Math Toolbox

Aprenda cálculo y matemáticas aplicadas usando Symbolic Math Toolbox™. Este ejemplo muestra las funciones introductorias fplot, diff e int.

Para manipular una variable, cree un objeto de tipo syms.

disp('Create a symbolic variable for x')
disp('>> syms x')
syms x
Create a symbolic variable for x
>> syms x

Después de definir una variable simbólica, puede construir y visualizar funciones con fplot.

disp('Build the function f(x) and plot it')
disp('>> f(x) = 1/(5+4*cos(x))')
disp('>> fplot(f)')
f(x) = 1/(5+4*cos(x))
figure;
fplot(f)
title('Plot of f(x)')
Build the function f(x) and plot it
>> f(x) = 1/(5+4*cos(x))
>> fplot(f)
 
f(x) =
 
1/(4*cos(x) + 5)
 

Evalúe la función en x = pi/2 usando notación matemática.

disp('Evaluate f(x) at x = pi/2')
disp('>> f(pi/2)')
f(pi/2)
Evaluate f(x) at x = pi/2
>> f(pi/2)
 
ans =
 
1/5
 

Muchas funciones pueden funcionar con variables simbólicas. Por ejemplo, la función diff diferencia una función.

disp('Differentiate f(x) and plot the result')
disp('>> f1 = diff(f)')
disp('>> fplot(f1)')
f1 = diff(f)
figure;
fplot(f1)
title("Plot of the derivative of f")
Differentiate f(x) and plot the result
>> f1 = diff(f)
>> fplot(f1)
 
f1(x) =
 
(4*sin(x))/(4*cos(x) + 5)^2
 

La función diff también puede encontrar la N-ésima derivada. El siguiente ejemplo muestra la segunda derivada.

disp('Compute the second derivative of f(x) and plot it')
disp('>> f2 = diff(f,2)')
disp('>> fplot(f2)')
f2 = diff(f,2)
figure;
fplot(f2)
title("Plot of the 2nd derivative of f(x)")
Compute the second derivative of f(x) and plot it
>> f2 = diff(f,2)
>> fplot(f2)
 
f2(x) =
 
(4*cos(x))/(4*cos(x) + 5)^2 + (32*sin(x)^2)/(4*cos(x) + 5)^3
 

La función int integra funciones de variables simbólicas. El siguiente ejemplo muestra un intento de recuperar la función original integrando dos veces la segunda derivada.

disp('Retrieve the original function by integrating the second derivative twice. Plot the result.')
disp('>> g = int(int(f2))')
disp('>> fplot(g)')
g = int(int(f2))
figure;
fplot(g)
title("Plot of int(int(f2))")
Retrieve the original function by integrating the second derivative twice. Plot the result.
>> g = int(int(f2))
>> fplot(g)
 
g(x) =
 
-8/(tan(x/2)^2 + 9)
 

Inicialmente, las gráficas de f y g son iguales. Sin embargo, sus fórmulas y los intervalos del eje y son diferentes.

disp('Observe the formulas and ranges on the y-axis when comparing f and g')
disp('>> subplot(1,2,1)')
disp('>> fplot(f)')
disp('>> subplot(1,2,2)')
disp('>> fplot(g)')
disp(' ')
figure;
subplot(1,2,1)
fplot(f)
title("Plot of f")
subplot(1,2,2)
fplot(g)
title("Plot of g")
Observe the formulas and ranges on the y-axis when comparing f and g
>> subplot(1,2,1)
>> fplot(f)
>> subplot(1,2,2)
>> fplot(g)
 

El valor e es la diferencia entre f y g. Tiene una fórmula complicada, pero su gráfica parece una constante.

disp('Compute the difference between f and g')
disp('>> e = f - g')
e = f - g
Compute the difference between f and g
>> e = f - g
 
e(x) =
 
8/(tan(x/2)^2 + 9) + 1/(4*cos(x) + 5)
 

Para mostrar que la diferencia es en realidad una constante, simplifique la ecuación.

disp('Simplify the equation to show that the difference between f and g is constant')
disp('>> simplify(e)')
e = simplify(e)
Simplify the equation to show that the difference between f and g is constant
>> simplify(e)
 
e(x) =
 
1