You are on page 1of 2

sample_program2.

% file = sample_program2.m % % Purpose: Use MATLAB as for array operations (i.e. vector processing) % % Written by: Mary Jordan, 9/25/07 % --------------------------------------------------------------% Clear the workspace clear all % Assignment statements for array variables x = [1 2 3 4 5] y = [10 20 30 40 50] z = 3 % array of 5 values % array of 5 values

% Compute variables R, S1, S2, T, U, V R = x+y S1 = 2*x S2 = x .* y T = x ./ y U = y .^ x V = z .^ x % addition, executed term-by-term % multiplication: scalar times array % multiplication: array times array % division: array divided by an array % exponent: array y raised to the power x % exponent: scalar z raised to the power x

% Compute the mean and standard deviation of array y % using built-in functions "mean" and "std" mean_y = mean(y) std_y = std(y) % Print the variables in the workspace to the screen whos % variable list is printed

% Plot X vs Y figure plot(x,S2,'b*--') grid on xlabel('Array x') ylabel('Array S2 = x.*y')

title('x vs. S2') % Save the plot to a digital file in your current directory print -dpng sample_plot.png % -------- end of program ----------------------------------------

You might also like