In: Computer Science
USING MATLAB
write a script that creates eight subplots(4x2). In each one, graph the values of sin(n(pi)x), where -1 <=x<=1, with an interval of 0.05 for n = 1 to 8.
there is no parenthesis on pi. I just didn't want to make it look like (npix) so it wouldn't be confusing to read.
Following is the code in eight_sines.m :
%
% Define the x-vector.
%
x = -1 : 0.05 : 1;
%
% We use a loop to draw the eight plots.
%
for n = 1 : 8
%
% Determine the y-vector.
%
y = sin(n .* pi .* x);
%
% Draw the plot.
%
%
% Choose the position.
%
subplot(4, 2, n);
plot(x, y);
title(['n = ', num2str(n),]);
grid on;
hold on;
end
Following is the run :
>>
>> eight_sines
>>