Trying to MATLAB code to find augmented matrix D, please help
Afficher commentaires plus anciens
What I currently have is
% Define the ordered bases
B = [1 0 4; 0 -3 1; 1 2 0];
C = [3; 2; -1; 5];
% Define the linear transformation
T = @(x) [x(1) + x(2); -2 * x(3)];
% Compute the images of the basis vectors in B under the transformation
B_images = zeros(2, size(B, 2));
for i = 1:size(B, 2)
B_images(:, i) = T(B(:, i));
end
% Create the augmented matrix D
D = [C, B_images];
% Display D
disp('Matrix D:');
disp(D);
and it gives me
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in solution (line 15)
D = [C, B_images];
I am trying to find the 2 x 5 matrix D, with these intructions,find the matrix represenatation for the linear transformation defined by T (x1 x2 x3) = {x1 + x2; -2x3} with respect to the ordered bases
B = [1 0 4; 0 -3 1; 1 2 0];
C = [3 2; -1 5];
3 commentaires
Dyuman Joshi
le 16 Fév 2024
Modifié(e) : Dyuman Joshi
le 17 Fév 2024
You defined C incorrectly, there are extra semi-colons in the definition. Remove them and the code runs -
% Define the ordered bases
B = [1 0 4; 0 -3 1; 1 2 0];
C = [3 2; -1 5];
% Define the linear transformation
T = @(x) [x(1) + x(2); -2 * x(3)];
% Compute the images of the basis vectors in B under the transformation
B_images = zeros(2, size(B, 2));
for i = 1:size(B, 2)
B_images(:, i) = T(B(:, i));
end
% Create the augmented matrix D
D = [C, B_images];
% Display D
disp('Matrix D:');
disp(D);
VBBV
le 16 Fév 2024
You defined B incorrectly May be you meant C incorrectly
Dyuman Joshi
le 17 Fév 2024
Réponses (1)
Let's compare the C matrix that you defined in your code:
C1 = [3; 2; -1; 5]
and the one defined by what I assume is the text of the assignment you were given:
C2 = [3 2; -1 5]
They aren't the same size. Can you place a 2-by-1 vector "side by side" with a 4-by-1 vector and have them "line up" without extra elements sticking out? To concatenate arrays in MATLAB, they have to have the same size in the dimension along which you're trying to concatenate them. So the following works; we're trying to put b and C2 side by side so they have to have the same number of rows:
b = [4; 6]
D = [b, C2]
This too would work because when putting b "on top" of C1 they have to have the same number of columns.
E = [b; C1]
But this wouldn't because b and C1 don't have the same number of rows. Nor would putting b "on top" of C2.
F = [b, C1] % error
G = [b; C2] % would also error
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!