MATLAB tutorial: how to plot a function of one variable

Math 331, Fall 2016 * Vitor Matveev * Lecture 1

We will make a simple plot of the following function for x in [-6, 6]

                      f(x) = sin(x^2) / x^2

Note that just a couple lines accomplish this task:

L = 6;
x = linspace(-L, L, 200);  % Create an array of "x" coordinates in [-6, 6]
y = sin(x.^2) ./ x.^2;     % IMPORTANT: note the periods "." in operations
plot(x, y, 'b-');          % Plot with a blue ("b") solid line ("-")
xlabel('x'); ylabel('y');
title('This is a simple plot of sin(x^2)/x^2');
axis([-L L -0.5 1.2]);     % Optional: specify coordinate window