Which are the result of taking the odds and even rows from respectively. Finally
ID: 1720799 • Letter: W
Question
Which are the result of taking the odds and even rows from respectively. Finally, computes matrix B which is the result of squaring each element of and adding each element of matrix N. For example, if: A = [1 2 3 4 5 3 7 8 9 10 11 12], then M = [1 2 3 7 8 9], N = [4 5 6 10 11 12], thus B = [1^2 + 4 7^2 + 10 2^2 + 5 8^2 + 11 3^2 + 6 9^2 +12] = [5 9 15 59 75 93], Below, was the code that one husky student made. However, he made five terrible mistake Prove that you can beat that husky by identifying his mistakes and fixing them.Explanation / Answer
Code for this program will be
clear all
close all
clc
A=input('Enter Matrix A ');
disp(A);
[R,C]=size(A)
M=A(1:2:R,:);
N=A(2:2:R,:);
B=M.*M+N;
disp('The Matrix B is :');
disp(B);
you have to give input as
[1,2,3;4,5,6;7,8,9;10,11,12]
for N,you used A(;,1:2:C) you should use A(2:2:R,:)
And Multiplication should be M.*M+N; (we need elements multiplication so,you should use ".", here M^2 ives matrix multiplication which is not possible since it is not a square matrix and even if it was square matrix it wouyld have given different results)
Other than that everything is fine.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.