98%(63)62 out of 63 people found this document helpful
This preview shows page 1 - 2 out of 2 pages.
% Part #1A=[1,4,2;2,5,8;3,6,9];B=[1,2,3;4,5,6;7,8,9];b=[4;23;27]; %Setting variables equal to matricesc=[4,3,2]; d=[1;2;3];A*BB*Ac*B %Perform the following operations: AB, BA, cB and AdA*dC=[A B]; % Construct a 3 × 6 matrix C = [A B ] and a 4 × 3 D=[B;c]; % matrix D =[B c]x=b\A; % Use the “backslash” command to solve the system Ax= bA(2,3)=0; %Replace A(2, 3) with 0.A(3,:); % Extract the 3rd row of the matrix A.B(3,:)=; %Delete the third row of the matrix B.%Part #2 All of the functions are at the bottom of the page, I wasn’tsure exactly how you wanted me to show you them, they are all there however. function1(1/2,10,3); %Write a function file (function1.m) that accepts the values of r, % a and n as arguments and uses a for loop to return the sum of the first% n terms of the geometric series. Test your function for a = 3, r = 1/2% and n = 10.function2(1/2,10,3); %Write a function file (function2.m) that accepts the values of r,% a and n as arguments and uses the built in command sum to find the sum% of the first n terms of the geometric series. Test your function for% a = 3, r = 1/2 and n = 10.%Part #3product = 1;for i = 1:2:10 %Write a script file that evaluates the product of the product=product*i %first 10 odd numbers using a for loopendprod(1:2:10) %Evaluate the product of the first 10 odd numbers using a% single MATLAB command. Use the MATLAB command prod.%Part #4N=1;V=while 2^N < 1000 % Write a script file that creates a row vector v N=N+1; % containing all the powers of 2 below 1000. The output vector V=[V,N];% should have the form: v = [ 2, 4, 8, 16 . . . ]. Use a while% loop.enddisp(V)%Part #5function3(1)Mat 275 MATLAB LAB #2 Name: Brandon Grebe Instructor: Anmin
function3(4) % Write a function file (function3.m) that creates the following function3(7) % piecewise functionfunction3(10)Function 1: function [S] = geosum(r,n,a)S=0;for k = 0:n-1 S=S+(a)*r^kendend Function 2: function [G] = geosum(r,n,a)e=0:n-1;R=a*r.^e;G=sum(R);endFunction 3: function y=f(x)if x==10disp('y is undefined at x = 10')else if x<=3y=x^2+1;else if x>3y=exp(x);else if x<=5y=exp(x)else x>5y=x/(x-10);endendendend