CS100M Spring 2004 A2 FAQ ------------------------------------------------------------------------------- Q) I'm getting a weird error in the velocity/height/acceleration problem. A) You might be multiplying t^2 wrong. There's a bit about matrices we haven't covered: If t = [1 2 3], then [1] [1] t*t means you are trying to do [2] [2], which is NOT a true dot product. [3] [3] You would need to say tt'. But, you don't even want a dot product in the first place. Instead, do t.*t (yes, ".*) for array multiplication, which multiplies each element of t by itself. ------------------------------------------------------------------------------- Q) When I try cos(pi/2) in MATLAB, it is not equal to zero. A) This is because of rounding errors in MATLAB. Write your code for the problem in question as if there were no rounding errors. I found that tan(90) did not produce an exceptional case, whereas tan(270) did. **In fact I had previously made a mistake. tan(270) does not execute the error branch either. Write the code so that it would print out the error if there was a case we could check. In other words, make sure you have an if statement for the error case. ------------------------------------------------------------------------------- Q) So wait, on the tangent question, does that mean I need to implement the if statement for the error case even if it doesn't get executed? A) Yes, implement the if statement for the error case for the tangent problem, even though it will not get executed for tan(90) for example. -------------------------------------------------------------------------------