Trying to MATLAB code to find augmented matrix D, please help
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Steven Lord
2024년 2월 16일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!