function simple_program % % This is prototype code you can use to write executable Matlab programs. In % Matlab if you want to comment out a line, you can use the % sign. % % Let's make some data and use commands that are necessary to do linear % regression x=[1:10]; % Generate a column vector with entries 1 to 5 y=[3:12]; % Generate a column vector with entries 3 to 8 sum(x) % Sume the elements sum(y) % Sum elements sum(x.^2) % Sum the square of the x elements x.*y % Do element-by-element multiplication. Does it match up? sum(x.*y) % Find a sum of element-by-element multiplication dot(x,y) % Do the dot product abs(-3) % The absolute value function. % Now we are going to make some simple plots. You can just adapt this code when % for your assignment. The first argument in the plot command is your x % variable, followed by your y variable, and plot options. The figure(1) % command preceding it opens a new window with the heading of Figure 1 figure(1); plot(x,y,'x'); % Plots x and y with crosses to denote data points. x1=x+3; y1=y-5; % Making some new data. % Plotting multiple data series on the same plot is easy. You have the same % basic setup: x_var, y_var, options and you just repeat it for as many plots you % wish to make. figure(2); plot(x,y,'x',x1,y1,'x'); % Once you have plotted something, use the GUI toolbar to add legends, axis % names, etc. % For part of your assignment you will write a for loop that calculates % the powers of a matrix and then multiply that matrix by a vector. Adapt this % code for your homework. A=[0.86 0.08; -0.12 1.14]; %A=[0 1; -0.12 0.5]; % Define a matrix x=[200;100]; % Define a vector n=10; % Number of iterations. result=zeros(2,n); % Assign a matrix that has as many columns as our iterations % and rows as the size of x for i=1:n y=A^i*x; % Find the ith power of A and multiply it by x result(:,i)=y; % Assign that result to our matrix. end % We wish to plot the first row of result against the second one. The plotting % command 'x-' adds connects the x's. figure(3); plot(result(1,:),result(2,:),'x-');