Calculus

Integration

Another easy and useful function of MuPad is integration . You can integrate with respect to any variable (even if previously not used). To make the same integral a definite integral, you can easily just add a few lines of code within the parenthesis of the function. MuPad also knows calculus and will follow the rules. The following code shows these properties:

eq:= x^4-3
\( \displaystyle x^4-3 \)
int(eq,x)
\( \displaystyle \frac{x\,\left(x^4-15\right)}{5} \)
int(eq,y)
\( \displaystyle y\,\left(x^4-3\right) \)
diff(int(eq,x),x)
\( \displaystyle x^4-3 \)
int(eq,x = 0..8)
or
int(eq,x,(0,8))
\( \displaystyle \frac{32648}{5} \)
Notice that to define the integrating parameters, we can use the notation x = 0..8. This directly translates to "where x is from 0 to 8."

Sometimes when you have a complicated integral, it is necessary to either simplify an answer or ignore some special cases that may occur (to avoid dividing by zero). Both of these actions can be executed by the command simplify and the parameter IgnoreSpecialCases or assume(condition). Recall that a command is a function that we will apply with parenthesis such as solve(...) and a parameter is a part of a command within the parenthesis that tells MuPad to do a certain task or follow a certain rule when executing the command.
problem1 := (x^3*sin(x*y/z))/(z^2)
\( \displaystyle \frac{x^3\,\sin\left(\frac{x\,y}{z}\right)}{z^2} \)
int(problem1,x)
\( \displaystyle -\frac{\sin\left(\frac{x\,y}{z}\right)\,\left(\frac{6\,z^4}{y^4}-\frac{3\,x^2\,z^2}{y^2}\right)}{z^2}-\frac{\cos\left(\frac{x\,y}{z}\right)\,\left(\frac{x^3\,z}{y}-\frac{6\,x\,z^3}{y^3}\right)}{z^2} \)
simplify(%)
\( \displaystyle -\frac{\sin\left(\frac{x\,y}{z}\right)\,\left(\frac{6\,z^4}{y^4}-\frac{3\,x^2\,z^2}{y^2}\right)}{z^2}-\frac{\cos\left(\frac{x\,y}{z}\right)\,\left(\frac{x^3\,z}{y}-\frac{6\,x\,z^3}{y^3}\right)}{z^2} \)
Notice that the simplify function created a common denominator. Sometimes it makes your answer cleaner, other times it won't. It is usually worth a shot to try when you have a complicated answer to any function.
problem2 := x*ln(x-y)/2
\( \displaystyle \frac{x\,\ln\left(x-y\right)}{2} \)
int(problem2,x)
\( \displaystyle \left\{\begin{array}{cl} \frac{x^2\,\left(\ln\left(x\right)-\frac{1}{2}\right)}{4} & \text{ if }\ y=0 , \\ \frac{\ln\left(x-y\right)\,\left(x^2-y^2\right)}{4}-\frac{y^2\,\left(\frac{x^2}{2\,y^2}+\frac{x}{y}\right)}{4} & \text{ if }\ y\neq 0 \end{array} \right. \)
int(problem2,x,IgnoreSpecialCases)
\( \displaystyle \frac{\ln\left(x-y\right)\,\left(x^2-y^2\right)}{4}-\frac{y^2\,\left(\frac{x^2}{2\,y^2}+\frac{x}{y}\right)}{4} \)
int(problem2,x,assume(y = 0))
\( \displaystyle \frac{x^2\,\left(2\,\ln\left(x\right)-1\right)}{8} \)
Notice in this case, we ended up with a conditional solution. This is great! MuPad is following the rules of mathematics. However, this can be very annoying, especially if some of the conditional answers are in the complex plane or don't have a solution (the empty set). The IgnoreSpecialCases parameter gives you a real answer and usually the most practical solution. If you know a physical condition that can't be broken (such that a time variable must be positive or zero), the "assume" parameter allows you to only solve for solutions within this condition.

Partial Differentiation

Differentiating functions in MuPad is quite easy. You do not have to declare a letter as a variable, it automatically assumes it as one. A string of letters (or just one symbol or character) will be taken as independent variables by default, but by using parenthesis you can define dependent variables. The only tricky part here is making sure that you derive with respect to the correct variable. The reason this is called "partial differentiation" instead of just "differentiation" is because you can differentiate equations of more than one variable - for example if you had an equation that mapped position, depending on both time and temperature.

First we must define the equation to differentiate

function := x^2+3*x-2
\( \displaystyle x^2+3\,x-2 \)
Notice that if we differentiate it with respect x, or t we will obtain different results. This is because we have not told MuPAD that x depends on another variable such as t, so it assumes that x is the independent variable of the equation.
diff(function, x)
\( \displaystyle 2x + 3 \)
diff(function, t)
\( \displaystyle 0 \)
In most cases, you will want to define your equation more explicitly -- instead of just x, we would write x(t). Notice that this time, MuPAD recognizes t as the independent variable of the equation.
function2 := x(t)^2+3*x(t)-2
\( \displaystyle {x\left(t\right)}^2+3\,x\left(t\right)-2 \)
diff(function2, x)
\( \displaystyle 0 \)
diff(function2, t)
\( \displaystyle 2\,x\left(t\right)\,\frac{\partial }{\partial t} x\left(t\right)+3\,\frac{\partial }{\partial t} x\left(t\right) \)
The power of MuPAD, however, is in the fact that you can perform these kinds of computations on very complicated equations, and even substitute in different values along the way
function3 := z(x,y)^4+sin(z(x,y))
\( \displaystyle \sin\left(z\left(x,y\right)\right)+{z\left(x,y\right)}^4 \)
diff(function3,x)
\( \displaystyle {z\left(x,y\right)}^3\,\frac{\partial }{\partial x} z\left(x,y\right)\,4+\cos\left(z\left(x,y\right)\right)\,\frac{\partial }{\partial x} z\left(x,y\right) \)
diff(%,y)
\( \displaystyle 4\,{z\left(x,y\right)}^3\,\frac{\partial }{\partial y} \frac{\partial }{\partial x} z\left(x,y\right)+\cos\left(z\left(x,y\right)\right)\,\frac{\partial }{\partial y} \frac{\partial }{\partial x} z\left(x,y\right)+{z\left(x,y\right)}^2\,\frac{\partial }{\partial x} z\left(x,y\right)\,\frac{\partial }{\partial y} z\left(x,y\right)\,12-\sin\left(z\left(x,y\right)\right)\,\frac{\partial }{\partial y} z\left(x,y\right)\,\frac{\partial }{\partial x} z\left(x,y\right) \)
subs(%,[z(x,y) = x^2+y^2])
\( \displaystyle 4\,{\left(x^2+y^2\right)}^3\,\frac{\partial }{\partial y} \frac{\partial }{\partial x} \left(x^2+y^2\right)+\cos\left(x^2+y^2\right)\,\frac{\partial }{\partial y} \frac{\partial }{\partial x} \left(x^2+y^2\right)+12\,{\left(x^2+y^2\right)}^2\,\frac{\partial }{\partial x} \left(x^2+y^2\right)\,\frac{\partial }{\partial y} \left(x^2+y^2\right)-\sin\left(x^2+y^2\right)\,\frac{\partial }{\partial y} \left(x^2+y^2\right)\,\frac{\partial }{\partial x} \left(x^2+y^2\right) \)