Trying to MATLAB code to find augmented matrix D, please help

10 Ansichten (letzte 30 Tage)
Ivan
Ivan am 16 Feb. 2024
Bearbeitet: Dyuman Joshi am 17 Feb. 2024
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 Kommentare
VBBV
VBBV am 16 Feb. 2024
You defined B incorrectly May be you meant C incorrectly
Dyuman Joshi
Dyuman Joshi am 17 Feb. 2024
Yes, thanks for the correction, @VBBV.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 16 Feb. 2024
Let's compare the C matrix that you defined in your code:
C1 = [3; 2; -1; 5]
C1 = 4×1
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]
C2 = 2×2
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]
b = 2×1
4 6
D = [b, C2]
D = 2×3
4 3 2 6 -1 5
This too would work because when putting b "on top" of C1 they have to have the same number of columns.
E = [b; C1]
E = 6×1
4 6 3 2 -1 5
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
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
G = [b; C2] % would also error

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by