MATH/CMSC 206 - Introduction to Matlab

Announcements Syllabus Tutorial Projects Submitting

Answers to Self-Test

1. This is actually easier than it seems at first. Notice that we have to turn our function into something symbolic by plugging in a symbolic variable x.

syms x;
f=@(x) exp(x)-x;
int(pi*f(x)^2,x,0,1)
 
ans =
 
(pi*(3*exp(2) - 13))/6
 

2. We have to vectorize because quad demands it! Also you may have to dig into a calculus book for the formula for the length of a curve. Also note that even though f is vectorized to start with, the process of doing f(x) undoes this and so we need to "revectorize".

syms x;
f=@(x) sin(x)./x;
ezplot(f,[1,10*pi])
quad(vectorize(sqrt(1+diff(f(x))^2)),1,10*pi)
ans =

   30.6466

3. This last one is tricky because we need to define our expression symbolically but then apply quad to it which demands a function handle only. We actually expected you to struggle with this one! Here we need the command matlabFunction which converts a symbolic expression to a file handle.

syms x;
f=x.^2+2.*x;
quad(matlabFunction(f),0,1.2)
ans =

    2.0160