Exercises

Please complete each exercise or answer the question before reviewing the posted solution comments.

  1. Write a script that calculates, displays and plots the squares of the numbers from -1000 to 1000. Save the script as squares1000.m and run your script from the editor window.

    screen shot of the program

    Did you remember to use element-wise operators to square your xdata? Did you create a separate variable for lastX? Creating a variable like this is preferrable to simply using the value in a calculation. By assigning the value to a name, you can "document" the use of the value in the context of your program. Also, you can reuse the variable later in the program, as we have demonstrated in the disp command.

    The syntax and use of the disp and num2str functions will be covered in the Output lesson topic discussion and examples.