This page introduces symbolic computation of antiderivatives as well as symbolic differential equation solvers which are suitable for initial value problems.
The symbolic toolkit contains a command int() for computing antiderivatives.
>> syms x >> int(x^2) ans = x^3/3
Notice that the int() command does not return the complete family of antiderivatives but rather a single representative. Adding an arbitrary constant produces the complete family.
Some elementary functions do not have elementary antiderivatives and consequently int() isn't always helpful.
>> syms x >> int( exp(sin(x)) ) Warning: Explicit integral could not be found. ans = int(exp(sin(x)), x)
If you feed int() an expression containing more than one symbolic parameter you should pass a second input specifying which parameter should be treated as the variable with respect to which an antiderivative is to be computed.
>> syms x u >> int(x*u, u) ans = (u^2*x)/2
You may pass an array of expressions to int().
>> syms x n k >> int([ x^n sin(k*x) cos(k*x) sec(k*x)^2 csc(k*x)^2 sec(k*x)*tan(k*x) csc(k*x)*cot(k*x)], x) ans = [ piecewise([n == -1, log(x)], [n ~= -1, x^(n + 1)/(n + 1)]), -cos(k*x)/k, sin(k*x)/k, tan(k*x)/k, -cot(k*x)/k, -2/(k*(tan((k*x)/2)^2 - 1)), -1/(k*sin(k*x))]
The solution set for a simple differential equation of the form ${\displaystyle \frac{dy}{dx} = f(x)}$ is nothing more or less than the family of antiderivatives of $f(x)$. If the differential equation is paired with a so-called initial condition to produce an initial value problem (IVP) ${\displaystyle \left\{\begin{array}{l} \frac{dy}{dx}=f(x) \\ y(x_0)=y_0 \end{array}\right.}$, then the solution is uniquely determined. The antiderivative of $f(x)$ which satisfies the initial condition $y(x_0)=y_0$ will not in general be the antiderivative produced by the int() command. You can, however, use the dsolve() command. For example, to solve the IVP ${\displaystyle \left\{\begin{array}{l} \frac{dy}{dx}=x^2 \\ y(1)=2 \end{array}\right.}$ with MATLAB's symbolic toolbox you could enter the commands shown below.
>> syms x y(x) >> dsolve( diff(y)==x^2, y(1)==2 ) ans = x^3/3 + 5/3
In fact the dsolve() command is rather more versatile than the example above may suggest. You may wish to revisit dsolve() when you study differential equations in detail in Ma240.