% help %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% help plot; helpwin plot; doc plot; % matrix operations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% A = [3 2; 2 4] b = [4; 3] c = A*b A = A^2; b = b.^2; x = A\b % solving linear equations b_test(1,1) = A(1,1)*x(1) + A(1,2)*x(2); b_test(2,1) = A(2,1)*x(1) + A(2,2)*x(2); b b_test % HW0.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Problem 1 sprintf('Problem 1') A=[-7, 1, 3; 0, -1, 0; 3, 0, 1]; % Coefficient matrix b=[4; -2; 6]; % RHS x=A\b; % x=inverse(A) * B sprintf('(a) The vector x is [%d, %d, %d]', x) sprintf('(b) The determinant of A is %d.', det(A)) pause; % Problem 2 sprintf('Problem 2') A=[-3, -3, -1; 0, -1, 0; 3, 1, 1]; sprintf('(a) The determinant of A is %d.', det(A)) v=null(A'); v=v/v(1); sprintf('The rank of A is %g.', rank(A)) sprintf('The null space of transpose of A is [%d, %g, %g]', v) sprintf('In general, there is no solution. There exists infinite solutions if [%d, %g, %g] x b = 0', v) A=[-4, 1, 3; 0, -1, 0; 3, 0, 1; 1, 0, 0]; v=null(A'); v=v/v(1); sprintf('The rank of A is %g.', rank(A)) sprintf('The null space of transpose of A is [%d, %g, %g, %g]', v) sprintf('In general, there is no solution. There exists one solution only if [%g, %g, %g, %g] x b = 0', v) pause; %Problem 3 sprintf('Problem 3') sprintf('(a) Columns of A are not linearly independent') sprintf('(b) Columns of A are linearly independent') % Problem 4 sprintf('Problem 4') A=[-3, -3, -1; 0, -1, 0; 3, 1, 1]; v=null(A); v=v/v(1); sprintf('(a) The null space of A is [%d, %g, %g]', v) sprintf('An orthogonal basis for the range space of A is ') R=orth(A) A=[-4, 1, 3; 0, -1, 0; 3, 0, 1; 1, 0, 0]; sprintf('(b) The null space of A is ') v=null(A) sprintf('An orthogonal basis for the range space of A is ') R=orth(A) A=[-4, 1, 3; 0, -1, 0; 3, 0, 1; 1, 0, 0]'; v=null(A); v=v/v(1); sprintf('(c) The null space of A is [%d, %g, %g, %g]', v) sprintf('An orthogonal basis for the range space of A is ') R=orth(A) % Visualization %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 2D plot x_points = [-10 : .05 : 10]; line = 5 .* x_points; parabola = x_points .^ 2; exponential = exp(x_points); absolute_value = abs(x_points); figure; subplot(2,2,1); plot(x_points,line); title('Here is the line'); subplot(2,2,2); plot(x_points,parabola); title('Here is the parabola'); subplot(2,2,3); plot(x_points,exponential); title('Here is the exponential'); subplot(2,2,4); plot(x_points,absolute_value); title('Here is the absolute value'); figure; hold on; plot(x_points,line,'r'); plot(x_points,parabola,'b'); plot(x_points,absolute_value,'m'); title('All in one!'); legend('line','parabola','absolute value') grid on; zoom on; % 3D % line plot Z = [0 : pi/50 : 10*pi]; X = exp(-.2.*Z).*cos(Z); Y = exp(-.2.*Z).*sin(Z); plot3(X,Y,Z); grid on; xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis');... title('A little more interesting!'); % Surface plots [X,Y] = meshgrid(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; mesh(Z); figure; surf(Z); % contour plots [X,Y,Z] = peaks; contour(X,Y,Z,20); % Vector fields n = -2.0:.2:2.0; [X,Y,Z] = peaks(n); contour(X,Y,Z,10); [U,V] = gradient(Z,.2); hold on quiver(X,Y,U,V)