Mat 275 Lab #2 - Mat 275 MATLAB LAB#2 Name Brandon Grebe Instructor Anmin Part#1 A=[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

Mat 275 Lab #2 - Mat 275 MATLAB LAB#2 Name Brandon Grebe...

This preview shows page 1 - 2 out of 2 pages.

% Part #1 A=[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 matrices c=[4,3,2]; d=[1;2;3]; A*B B*A c*B %Perform the following operations: AB, BA, cB and Ad A*d C=[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 = b A(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’t sure 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 #3 product = 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 loop end prod(1:2:10) %Evaluate the product of the first 10 odd numbers using a % single MATLAB command. Use the MATLAB command prod. %Part #4 N=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. end disp(V) %Part #5 function3(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 function function3(10) Function 1: function [S] = geosum(r,n,a) S=0; for k = 0:n-1 S=S+(a)*r^k end end Function 2: function [G] = geosum(r,n,a) e=0:n-1; R=a*r.^e; G=sum(R); end Function 3: function y=f(x) if x==10 disp( 'y is undefined at x = 10' ) else if x<=3 y=x^2+1; else if x>3 y=exp(x); else if x<=5 y=exp(x) else x>5 y=x/(x-10); end end end end

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture