Exercises
Please complete each exercise or answer the question before reviewing the posted solution comments.
-
Write a script that calculates, displays and plots the squares of the numbers from -1000 to 1000. Save the script as
squares1000.mand run your script from the editor window.
Did you remember to use element-wise operators to square your
xdata? Did you create a separate variable forlastX? 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 thedispcommand.The syntax and use of the
dispandnum2strfunctions will be covered in the Output lesson topic discussion and examples.