[Content_Types].xml
_rels/.rels
matlab/document.xml
matlab/output.xml
metadata/coreProperties.xml
metadata/mwcoreProperties.xml
metadata/mwcorePropertiesExtension.xml
metadata/mwcorePropertiesReleaseInfo.xml
MATLAB Integration In this livescript, you will learn how To compute integrals using both the numeric and symbolic packages in MATLAB. Numeric Integration We’ll consider the integral of the function f(x)=\frac{1}{x} over the interval x\in[1,2] . (a) Compute the integral \int^{2}_{1}{f(x)dx} analytically. The simpliest way of doing this in MATLAB is to use the \texttt{integral(fun,xmin,xmax)} function. It works by using an adaptive quadrature, which works by adapting the mesh so that even badly behaved functions may admit an integral. It takes the inputs \texttt{fun} , which is an anonymous function, and the integral limits \texttt{xmin} and \texttt{xmax} . For our example q = integral(@(x)1./x,1,2) (b) Run the previous command and verify that it gives the same answer as part (a). However, most of the time you won’t have a function to integrate, just a set of points. For example, if you measured the acceleration of a car at discrete points in time, then your data may look like t = linspace(0,1,10);
a = t+0.1*rand(1,10)-0.1*rand(1,10);
plot(t,a,’x’) If we want to determine the integral of a function given in terms of values at grid points, we first need to interpolate the function and then integrate it. In MATLAB, the function \texttt{trapz(X,Y)} does so assuming that the variation between each grid point is linear (i.e. the Trapezoid rule). (c) Use the trapezoid rule with a single interval to estimate \int^{2}_{1}{\frac{1}{x}dx} \texttt{trapz()} take the inputs \texttt{X} , which is a vector of the grid points, and \texttt{Y} , which is a vector of the function values at \texttt{X} . If we consider a single interval, we have X = [1,2];
Y = 1./X; Hence, \texttt{trapz()} gives trapz(X,Y) (d) Run this command and verify your solution in (c). (e) Modify the previous command to the apply the Trapezoidal rule with 5 intervals. Symbolic Integration While MATLAB is usually used for numerics, it does have some symbolic capabilities that you can use in case you ever want to compute indefinite integrals for fun (or maybe a maths assignment). To use to symbolic package, we first need to tell MATLAB that a given variable is symbolic, which can be done using \texttt{syms} . For example, to set \texttt{x} as a symbolic variable syms x Then, we can compute the definite integral \int^{2}_{1}{\frac{1}{x}dx} using \texttt{int()} int(1/x,x,[1,2]) (f) Run the previous command and verify it gives the desired result. And if you’re just looking for the indefinite integral int(1/x) There are plenty of features that \texttt{int()} can do; including integration by parts, Cauchy principle values, etc. which you can read about here .
manual code ready 0.4 true true q = integral(@(x)1./x,1,2) 0 16 16 true false t = linspace(0,1,10); 1 21 21 false false a = t+0.1*rand(1,10)-0.1*rand(1,10); 2 22 22 false true plot(t,a,’x’) 3 24 24 true false X = [1,2]; 4 33 33 false false Y = 1./X; 5 34 34 false true trapz(X,Y) 6 36 36 true false syms x 7 44 44 false true int(1/x,x,[1,2]) 8 48 48 true true int(1/x) 9 53 53
2020-04-21T18:22:23Z 2020-09-13T02:36:33Z
application/vnd.mathworks.matlab.code MATLAB Code R2020a
9.8.0.1298242 5479b6c0-1913-4234-aa87-dbb49df648eb
9.8.0.1446778
R2020a
Update 5
Jul 30 2020
2676164157