Exam solutions, Moed Aleph, 5769

These are only notes, not full answers.
All the questions can be answered in many ways! Especially the ones in part B.

==============================================================================

SECTION A, QUESTION 1
=====================

To get the plot 
x=[1,2,0,1];   % take the first point again at end 
y=[2,0,1,2];
z=[0,1,2,0];
plot3(x,y,z)

To get the area
p1=[1;2;0];
p2=[2;0;1];
p3=[0;1;2]; 
norm( cross(p1-p3,p2-p3), 2)/2 

==============================================================================

SECTION A, QUESTION 2
=====================

with(LinearAlgebra);
A:=<<1,2,-5>|<-7,0,3>|<2,4,1>>;
b:=<-3,1,6>;
x:=LinearSolve(A,b);
If there is no solution this will give an error
If there is more than one solution it will give all of them.
So if it gives just one, there is just one! 

I took off points if you used the determinant or something similar
to check uniqueness of solution, it is not necessary. 

==============================================================================

SECTION A, QUESTION 3
=====================

function z=q3(x)
a=eig( [ 1 -7 2 ; -7 x 4 ; 2 4 1 ] ); 
z=max(a);

==============================================================================

SECTION A, QUESTION 4
=====================

Since |y|<=x and x<=pi, -pi<=y<=pi
Set up the following function:

function  z=q4(x,y)
z=zeros(size(x));
for i=1:size(x,1)
   for j=1:size(x,2)
      if abs(x(i,j))<y 
         z(i,j)=cos(x(i,j)*sin(y));
      end
   end
end

and then do  dblquad(@q4,-pi,pi,0,pi)  to get the integral 

==============================================================================

SECTION A, QUESTION 5
=====================

Set up the following function:

function z=q51(x,p)
   z=-(x+3)/(1+4*sin(x)^2+p*x^2);
   
The required function is as follows 

function z=q52(p)
   [w z]=fminsearch(@q51,0,[],p); 
   z=-z;       % don't forget you are using - the real function!

==============================================================================

SECTION A, QUESTION 6
=====================

Digits:=20
f:=(x+3)/(1+4*sin(x)^2) - 2;
g:=diff(f,x);
   
to find the roots do
r1:=fsolve( f=0, x=-1..0 );   
r2:=fsolve( f=0, x=0..1  );  
r3:=fsolve( f=0, x=2..3  );

to find the critical points do 
c1:=fsolve( g=0, x=-1..1 );   
c2:=fsolve( g=0, x=1..2  );  
c3:=fsolve( g=0, x=-3..-1  );    not clear if there is something there

and get values of f by subs(x=c1,f); subs(x=c2,f); subs(x=c3,f); 

==============================================================================

SECTION B, QUESTION 1
=====================

a)
f:=piecewise(x>=0 and x<=4, exp(-x/2), x>4, 1/(a+b*x^2+c*x^4) );
f1:=diff(f,x);
f2:=diff(f1,x);
e1:= limit(f,x=4,left)=limit(f,x=4,right);
e2:= limit(f1,x=4,left)=limit(f1,x=4,right);
e3:= limit(f2,x=4,left)=limit(f2,x=4,right);
solve( {e1,e2,e3} , {a,b,c} );     might want to use fsolve

b) No reason not to try the same thing: 
qb1:=proc(z,p);
local f,f1,f2,e1,e2,e3;
f:=piecewise(x>=0 and x<=p, z, x>p, 1/(a+b*x^2+c*x^4) );
f1:=diff(f,x);
f2:=diff(f1,x);
e1:= limit(f,x=4,left)=limit(f,x=p,right);
e2:= limit(f1,x=4,left)=limit(f1,x=p,right);
e3:= limit(f2,x=4,left)=limit(f2,x=p,right);
return(solve( {e1,e2,e3} , {a,b,c} ));    
end proc;

c) Many students wrote "no" as z might not be well-defined or
twice differentiable at p (or somewhere in [0,p]). This is true but 
is not what I was looking for.
Some students wrote that if z=0 at x=p then it is not possible
to find a,b,c. This is better. 
The points is that there are 3 equations in 3 variables a,b,c. It
is not clear there is a solution, whether it is unique, or 
whether solve will find it (and we might need fsolve). In fact
unless z=0 at x=p there is a unique solution. We are trying to
solve    z(p) = 1/f(p)       (where f is linear in a,b,c) 
         z'(p) = -f'(p)/f(p)^2 
         z''(p) = -f''(p)/f(p)^2 + 2f'(p)^2/f(p)^3 
=>   f(p) = 1/z(p) 
        f'(p) = -z'(p)/z(p)^2 
        f''(p) = -z''(p)/z(p)^2 + 2z'(p)^2/z(p)^3  
there is a unique solution provided z(p)=0. 
I was not expecting people to get this far - but I was expecting 
mention of the possibility of no solution, or of more than one, 
the need to use fsolve, and the difficulty in chosing an initial 
guess for a solution. 

==============================================================================

SECTION B, QUESTION 2
=====================

a) If p(x) = p1 x^n + p2 x^{n-1} + .... + pn x + p(n+1)
   then  integral p(x) dx =   ( p1 b^(n+1)/(n+1) + p2 b^n/n + ... + p(n+1) b )
                            - ( p1 a^(n+1)/(n+1) + p2 a^n/n + ... + p(n+1) a )

function z=qb21(p,a,b)
n=length(p)-1;
z=0;
for i=1:(n+1)
    z=z+p(i)*(b^(n+2-i)-a^(n+2-i))/(n+2-i);
end

b) 
function A=qb22(p,q)

% make r=p-q - be careful: 
np=length(p)-1;
nq=length(q)-1;
if np>=nq
   r=p;
   for i=0:nq
       r(np+1-i)=r(np+1-i)-q(nq+1-i);
   end
else
   r=q;
   for i=0:np
       r(nq+1-i)=r(nq+1-i)-p(np+1-i);
   end
end

% make the real roots of r and order them 
xs=roots(r);
realxs=[];
for i=1:length(xs)
    if imag(xs(i))==0
       realxs=[realxs,xs(i)];
    end
end
realxs=sort(realxs);

% add up the areas, using qb21
A=0;
for i=1:(length(realxs)-1)
   A=A+abs(qb21(r,realxs(i),realxs(i+1));
end

==============================================================================

SECTION B, QUESTION 3
=====================

a) 
d:=0;
thei:=1;
thej:=1; 
for i from 1 to nops(P) do 
    for j from 1 to nops(Q) do 
        p:=op(i,P);
        q:=op(j,Q);
        newd:=evalf( sqrt( (op(1,p)-op(1,q))^2 +(op(2,p)-op(2,q))^2 ) );
        if newd>d then 
             d:=newd;
             thei:=i;
             thej:=j;
        end if;
    end do;
end do; 
Pmax:=op(thei,P);     this is the point we want in P
Qmax:=op(thei,P);     this is the point we want in Q

THERE MIGHT BE MANY SUCH POINTS! 

b)   very similar 
d:=infinity;
thei:=1;
thej:=1; 
for i from 1 to nops(P) do 
    for j from 1 to nops(Q) do 
        p:=op(i,P);
        q:=op(j,Q);
        newd:=evalf( sqrt( (op(1,p)-op(1,q))^2 +(op(2,p)-op(2,q))^2 ) );
        if newd<d then 
             d:=newd;
             thei:=i;
             thej:=j;
        end if;
    end do;
end do; 
Pmin:=op(thei,P);     this is the point we want in P
Qmin:=op(thei,P);     this is the point we want in Q

THERE MIGHT BE MANY SUCH POINTS! 

c)
with(plots):

make 4 plots, of the 2 sets of points and the 2 lines, and display them 

pl1:=plot(P,style=point,color=red);
pl2:=plot(Q,style=point,color=blue);
pl3:=plot([ op(1,Pmin)+t*(op(1,Qmin)-op(1,Pmin)) ,op(2,Pmin)+t*(op(2,Qmin)-op(2,Pmin)) , t=0..1])
pl4:=plot([ op(1,Pmin)+t*(op(1,Qmin)-op(1,Pmin)) ,op(2,Pmin)+t*(op(2,Qmin)-op(2,Pmin)) , t=0..1])
display(p1,p2,p3,p4) 

==============================================================================


Back to course homepage
Back to my teaching homepage
Back to my homepage