Need help with following MatLab Problems close all; clear all; % This is a script.
Question:
Need help with following MatLab Problems
close all;
clear all;
% This is a script. It is a useful way to write many MATLAB commands and
% then run them all at once. Later we will also use scripts to write
% functions, creating tools that we could use later in future scripts
%
% In class we saw how to:
% -Create variables
% -Create vectors
% -Access entries of vectors
% -Add vectors
% -Multiply vectors by scalars
% -Plot points and vectors
% -Write simple for loops
%
% Here we will explore linear combinations of vectors, with a particular
% focus on the number of dimensions a fixed set of given vectors can 'span'.
%% Linear combination of two vectors in 2D #1
% Here we want to consider different linear combinations of two vectors in
% 2D. Our vectors will be v1 = [1,2] and v2 = [4,-1]. Produce a plot
% showing the original vectors using the quiver command and 100 different
% random linear combinations of those two vectors using plot.
v1 = [1,2];
v2 = [4,-1];
figure();
title('The linear combinations of 2 vectors');
hold on;
for i=1:100
c = 2*rand(1,2)-1;
x = c(1).*v1 + c(2).*v2;
plot(x(1),x(2),'ro')
end
quiver(0,0,v1(1),v1(2),'b','linewidth',2);
quiver(0,0,v2(1),v2(2),'k','linewidth',2);
%% Questions
% #1: Can any vector in the plane be expressed as a linear combination of
% of v1 and v2? Why do you think that?
%
% Answer: I do think that any vector in the plane can be expressed as a
% linear combination since v1 and v2 are linearly independent of eachother
%
% #2: How would the plot look different if the coefficients c were sampled
% differently? For instance, what happens if c = 10*rand(1,2)
%
% Answer:
%% Linear combination of two vectors in 2D #2
% Here we want to consider different linear combinations of two vectors in
% 2D. Our vectors will be v1 = [1,2] and v2 = [-2,-4]. Produce a plot
% showing the original vectors using the quiver command and 100 different
% random linear combinations of those two vectors using plot.
v1 = [1,2];
v2 = [-2,-4];
figure();
title('The linear combinations of 2 vectors');
hold on;
for i=1:100
c = 2*rand(1,2)-1;
x = c(1).*v1 + c(2).*v2;
plot(x(1),x(2),'ro')
end
quiver(0,0,v1(1),v1(2),'b','linewidth',2);
quiver(0,0,v2(1),v2(2),'k','linewidth',2);
%% Questions
% #3: Can any vector in the plane be expressed as a linear combination of
% of v1 and v2? Why do you think that?
%
% Answer:
%
% #4: Looking back at v1 and v2, what about those vectors explains why this
% is differrent than the first set of v1 and v2.
%
% Answer:
%
% #5: Why do the red points extend beyond both v1 and v2?
%
% Answer:
%% Linear combination of two vectors in 3D #1
% Here we want to consider different linear combinations of two vectors in
% 3D. Our vectors will be v1 = [1,2,0], and v2 = [4,-1,2]. Produce a plot
% showing the original vectors using the quiver3 command and 100 different
% random linear combinations of those two vectors using plot3.
v1 = [1,2,0];
v2 = [4,-1,2];
figure();
title('The linear combinations of 2 vectors in 3D');
hold on;
for i=1:100
c = 2*rand(1,2)-1;
x = c(1).*v1 + c(2).*v2;
plot3(x(1),x(2),x(3),'ro')
end
quiver3(0,0,0,v1(1),v1(2),v1(3),'b','linewidth',2);
quiver3(0,0,0,v2(1),v2(2),v2(3),'k','linewidth',2);
view(3)
%% Questions
% #6: What vectors in 3-spaces can be expressed as a linear combination of
% of v1 and v2? Why do you think that, and could you predict that from the
% problem setup?
%
% Answer:
%% Linear combination of three vectors in 3D #2
% Here we want to consider different linear combinations of three vectors in
% 3D. Our vectors will be v1 = [1,2,0], v2 = [4,-1,0] and v3 = [0,0,1]. Produce a plot
% showing the original vectors using the quiver3 command and 100 different
% random linear combinations of those two vectors using plot3.
%Please write code
%% Questions
% #7: Can all vectors in 3-space be expressed as a linear combination of
% of v1, v2 and v3? Why do you think that and could you predict that from
% the problem setup?
%
% Answer:
%% Linear combination of three vectors in 3D #3
% Here we want to consider different linear combinations of three vectors in
% 3D. Our vectors will be v1 = [1,2,0], v2 = [4,-1,2] and v3 = [-5,-1,-2]. Produce a plot
% showing the original vectors using the quiver3 command and 100 different
% random linear combinations of those two vectors using plot3.
%Please write code
%% Questions
% #8: Can any vector in 3-space be expressed as a linear combination of
% of v1, v2 and v3?
%
% Answer:
%
% #9: Why is your answer to #8 different to your answer to #7 and could you
% tell from equations for v1, v2 and v3 that this would be the outcome?
%
% Answer:
International Marketing And Export Management
ISBN: 9781292016924
8th Edition
Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr