MATH/CMSC 206 - Introduction to Matlab
Announcements | Syllabus | Tutorial | Projects | Submitting |
Answers to Self-Test
1. This is pretty straightforward. We get infinitely many solutions of course:
evalin(symengine,'solve(sin(2*x)-cos(x)=0,x)')
ans = {pi/2 + 2*pi*k | k in Z_} union {pi/6 + (2*pi*k)/3 | k in Z_}
2. By now you know how to open a notebook. Within the notebook:
f:=x->exp(x^2+x)
k:=diff(f(x),x)|x=1
And then back in Matlab:
k=getVar(nb,'k') |
k = 3*exp(2) |
3. Within the notebook:
y:=int(x*sin(x)*cos(x),x)
And then back in Matlab:
f=matlabFunction(getVar(nb,'y')) |
f = @(x)sin(2.*x)./8-(x.*cos(2.*x))./4 |
Note that we need the matlabFunction command to turn the symbolic expression from MuPAD into a function handle.
4. First we execute in Matlab:
syms x; y=1/x+exp(1-x); setVar(nb,y); |
And then in the MuPAD notebook:
j:=int(y,x=1..3)
And then finally back in Matlab:
t=getVar(nb,'j') |
t= log(3)-1/exp(2)+1 |