computed the left side and right side matriecs
Show older comments
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;
Answers (1)
KSSV
on 26 Aug 2022
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;
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!