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.m
and 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 thedisp
command.The syntax and use of the
disp
andnum2str
functions will be covered in the Output lesson topic discussion and examples.