computed the left side and right side matriecs

Can anyone help me to explain what's the problem on this question where I already computed both side matrices but run script show its incorrect.Thank you!
Question below:
  • computed the left hand side and the right hand side of the equation and store them in the variables LHS1,RHS1,LHS2,RHS2 ans so on
  • use the logical operator == to determine whether the statements below are true or false. LHS==RHS does element by element comparison between the variables LHS and RHS and returns an array with elements set to 1(true) where the relation is true and element set to 0(false) where it is not. store the result of question 1 in the variables ans1, and so on.
Answer below:
A=[-2,1,-4,2 ];
B=[-1,-2,-3,-6];
C=[-2,-6, 1,3];
LHS1=A*(B+C);
RHS1=A*B+A*C;
ans1=LHS1==RHS1;
LHS2=A*(B+C);
RHS2=B*A+C*A;
ans2=LHS2==RHS2;
LHS3=(A+B)*(A+B);
RHS3=A*A+2*A*B+B*B;
ans3=LHS3==RHS3;
LHS4=(A*B)*(A*B);
RHS4=(A*A)*(B*B);
ans4=LHS4==RHS4;
LHS5=(A-B)(A+B);
RHS5=(A*A)-(B*B);
ans5=LHS5==RHS5;

1 Comment

Never mind, all. I think I figured it out already. Thank you anyway!

Sign in to comment.

Answers (1)

Read about matlab array element by element operations. You need to use .*. At one place, you have missed * operator. Consider using isequal whie comparing using ==.
A=[-2,1,-4,2 ];
B=[-1,-2,-3,-6];
C=[-2,-6, 1,3];
LHS1=A.*(B+C);
RHS1=A.*B+A.*C;
ans1=LHS1==RHS1;
LHS2=A.*(B+C);
RHS2=B.*A+C.*A;
ans2=LHS2==RHS2;
LHS3=(A+B).*(A+B);
RHS3=A.*A+2*A.*B+B.*B;
ans3=LHS3==RHS3;
LHS4=(A.*B).*(A.*B);
RHS4=(A.*A).*(B.*B);
ans4=LHS4==RHS4;
LHS5=(A-B).*(A+B);
RHS5=(A.*A)-(B.*B);
ans5=LHS5==RHS5;

Tags

Asked:

on 26 Aug 2022

Commented:

on 26 Aug 2022

Community Treasure Hunt

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

Start Hunting!