Homework 3 frequently asked questions and answers

  1. Q: I am trying to save my graphs with a format other than Jpg. but I am having some trouble. Because PDF doesnt open in word, and there is no Gif.
  2. Q: On the final section of the homework (section 2.7) I attempted the calculation and got an error message of "the matrix sizes must agree". I am not sure, exactly on how to get them to agree, can you help me?
  3. Q: I had a little trouble with the norm fxn, and I was wondering if to calculate the norm you need to sqaure the difference your self or if matlab knows to square it when it runs its norm()
  4. Q: I don't understand what the scaler value from the norm-error represents. How can I get a number that is larger than the largest number in the data?
  5. Q: When you say write down the equation for the mean and standard deviation -
    do you mean like write it down by hand, or like in matlab code?
  6. Q: How do you make a table of the results with mean, median and std on
    the top and the variables on the left.?
  7. You say in the Hw "Do this by taking the linear and nonlinear fits performed above (you have an
    equation from when you created the plots) and using them to compute predicted
    y-values given the x-values of the data. Then make a new variable such as NBE by
    subtracting actual y minus predicted y, then squaring those values. Finally compute
    the norm of those quantities with the norm command in matlab." which makes me think you take the difference then square that then take the norm...but thats not hoe the norm function works in mat lab because norm() calculates the square for you....
  8. i don't get how i can get the dimensions to agree for the last problem


Q: I am trying to save my graphs with a format other than Jpg. but I am having some trouble. Because PDF doesnt open in word, and there is no Gif.

A: save as EPS, then insert by insert-picture-from file


Q: On the final section of the homework (section 2.7) I attempted the
calculation and got an error message of "the matrix sizes must agree". I
am not sure, exactly on how to get them to agree, can you help me?

norm(NBE.^2)
plot(height,norm,'r')

A: You need to store the results of the norm calculation in a variable. You're trying to plot a function as if it was a variable, so you need to do something like myvariable = norm(blah). Also you don't have to square the differences, that's part of the norm equation.


Q: I had a little trouble with the norm fxn, and I was wondering if to calculate the norm you need to sqaure the difference your self or if matlab knows to square it when it runs its norm()

A: You don't need to square the differences before putting them into the norm function. I'd do it like this:

NBE = norm(y_data-y_model);
Remember the equation for a norm = ( sum_{over all i} (d_i^2) )^0.5
Look up norm at mathworld.com for a bit of clarification


Q: I don't understand what the scaler value from the norm-error represents. I followed the
steps in the homework : I
computed the predicited y values using linear and quadratic least squares, then subtracted
those values from the
actual y values, squared the results, and then plugged the vector into the norm() function).
The final answer I got
was like 52.something for the linear error (im not in the lab so I can't check the exact
number) and 50.3something
for the non-linear/quadratic error.

So, I don't know if I computed the values right. Do I take the square root of that number?
What does the number
conceptually mean? That the total sum of all errors is 50, or that the greatest error is 50?
But I dont get how I can
have an error of 50 given that the actual y values(shoe size) range from like 20 to 40, and the
fits follow the data
pretty well.

A: The norm error represents a sum over all the values of the difference between the actual data and model. You compute the difference, then plug that difference into the norm, you don't have to square the difference in this case (the norm computes the square root of the sum of the squares of the elements of an array - go to mathworld.com and look up 'norm'). So by the squared part of the equation, errors always accululate, whether + or -, they are always differences between actual and modeled data. Thus a larger number means there is more overall difference between model and data, so we want the smallest cumulative error possible. So adding up some small number over a lot of data points adds up to a bigger number (ie if all the differences between measured and modeled data are 0.1, and there are 1000 points, that becomes a large number).


Q: When you say write down the equation for the mean and standard deviation -
do you mean like write it down by hand, or like in matlab code?

A: Write the equations in something like word equation editor (insert-object-microsoft word equation).


Q: How do you make a table of the results with mean, median and std on
the top and the variables on the left.?

A: Use word or excel to create the table, and write in the data by hand, probably the easiest method here.


Q: You say in the Hw "Do this by taking the linear and nonlinear fits performed above (you have an
equation from when you created the plots) and using them to compute predicted
y-values given the x-values of the data. Then make a new variable such as NBE by
subtracting actual y minus predicted y, then squaring those values. Finally compute
the norm of those quantities with the norm command in matlab." which makes me think you take the difference then square that then take the norm...but thats not hoe the norm function works in mat lab because norm() calculates the square for you....

A: Yes it's a typo, you don't have to square the difference before norming.  Actually you CAN if that's the way you want to define the error, it's arbitrary (it depends on whether you want to be in a particular error space or another actually, but that decision generally is up to the scientist).  Either way you will get the same relationship roughly, it's just a different scale.  I'm making a FAQ like hw2, and just now putting it up.  I realized I had that typo, and many people have already used that definition of the error, so I'll accept either approach.


Q: i don't get how i can get the dimensions to agree here:

NBE2=shoesize-qls
norm(NBE2)

??? Error using ==> minus
Matrix dimensions must agree.

A: The problem is that you probably generated a another group of x values after making your fit, plugged it in and got some ypredicted to make your plots, but now that has more points than the original data (do a 'whos' to confirm this). So once you have your fit and plots, generate the predicted y values by taking your fit equation, plugging in the x data, and getting ypredicted (for you lls and qls). You may want to clear the variable first to make sure the size is correct (it had more values in the variable, and matlab may leave the size larger, though you recompute the y values and store them in the earlier spaces in the variable). That should take care of your problem.

If you get matrix dimensions disagreeing, be sure to check the sizes of all your variables by typing 'whos' at the command prompt to see all your variable sizes that are in memory.