% Remember to try your answers on your OWN command line! If it doesn't work for you, it's unlikely to work for Cody. If you misspell the name of a function, you better catch it yourself! W4Q1: Find a median This wasn't half as tricky as you may have thought. Turns out that the PRCTILE function is not available under Cody. Hence I asked for the 50th percentile, which is the median! % My solution v=1:100; w=linspace(0,1,length(v)); vw=v.^w; vp=median(vw); % This might have been correct if Cody had the STATS toolbox: vp=prctile(vw,50); W4Q2: Make a histogram % Most of you had absolutely no problem with this one v='FREDERIK'; va=abs(v); vh=hist(va,4); vl=max(vh); W4Q3: Calculate a correlation % Same here, most people had this very thing without any trouble x1=[ 1 5 -6 8 9 2 0 -2 18 29 54]; x2=[-1 4 -6 4 12 -2 3 -2 33 19 47]; R=corrcoef(x1,x2); r=R(2); W4Q4: Fit a polynomial % The important lesson here is that any number N of data can be exactly represented by a polynomial of degree N-1, i.e. by an INTERPOLATING polynomial, which will then hit all the requested values without any error. % My solution x=[ 1 2 3 4 5 6 7 8]; y=[70 82 69 68 69 82 73 75]; N=length(x); P=polyfit(x,y,length(x)-1); yval=P(1)*x(1)^7+... P(2)*x(1)^6+... P(3)*x(1)^5+... P(4)*x(1)^4+... P(5)*x(1)^3+... P(6)*x(1)^2+... P(7)*x(1)^1+... P(8)*x(1)^0; r=abs(y(1)-yval); % Some people tried to use a function called RESID. That being an incredibly high-level and sophisticated function - impossible to apply correctly unless you really read up on it. % Some tried to stick in the value r=0 % which, obviously, cheats the test. Not allowed! % Some of you got lucky with r=yval-y(1); % but really, the question and your query should be about the ABSOLUTE residual! W4Q5: Evaluate a polynomial % My solution P=[17/280 -271/144 5743/240 -23209/144 49433/80 -12028/9 622691/420 -619]; Pd=length(P)-1; x=1:8; Px=polyval(P,x); Pc=char(round(Px)+64); % Some people tried the function COUNT instead of LENGTH, which I didn't know, but isn't the right thing for this problem. % It might have been a giveaway that the correct answer spelled my own name. Those of you who had 'FREDERI' but not 'FREDERIK' should have caught it yourselves.