Differentiation and integration

In MATLAB, you can differentiate and integrate symbolic expressions. We illustrate these commands by means of an example:
>> syms x y
>> y = atan(x)
Differentiating $ y$ with respect to $ x$ , respectively, once and three times:
>> diff(y,x)

ans =

>> diff(y,x,3)

ans =
The indefinite integral $ \int \arctan(x)dx$ :
>> int(y,x)

ans =
The definite integral $ \int^{7}_{2} \arctan(x)dx$ :
>> int(y,x,2,7)

ans =
This is the exact value of the integral. The numerical value is obtained by
>> double(ans)

ans =
The command double gives the numerical value of an exact number.

By far most integrals cannot be calculated explicitly. Consider the example of trying to calculate the integral of ` $ f(x) = e-x(1+x^{3})^{1/2}$ ' over the interval [1,4].

>> int(exp(-x)*sqrt(1+x^3),x,1,4)

ans =
    int(exp(-x)*(1+x^3)^(1/2),x = 1..4)

>> double(ans)

ans =
MATLAB returns the integral, because it cannot calculate it explicitly. The function double gives a numerical approximation of the integral.

Previous      Next      Up      Contents

Esteur 2010-03-22