Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im trying to calculate a matrix in MATLAB and for some reason it is not working!

ID: 3558218 • Letter: I

Question

Im trying to calculate a matrix in MATLAB and for some reason it is not working! Im trying to find a way to multiply two matrices together with one the matrices having variabes that are arrays.Each of the values within each array (r1 through r5 from my code) need to be multiplied by the values given by the second matrix. I need to plot all of the values as well. I keep getting an error sayig "Error using vertcat. Dimensions of matrices being concatenated are not consistent." Here is my code:

r1=[2:2:10];
r2=[3:3:15];
r3=[4:4:20];
r4=[5:5:25];
r5=[6:6:30];
i1=10;
i2=15;
i3=20;
A=[r1,r2,0;r1,r4,r3;r2,r3,r5];
B=[i1-i2,i1-i3,0;i2-i1,i2,i2-i3;i3-i1,i3-i2,i3];
C=A.*B

Please Help!

Explanation / Answer

Here is the correct code:

Changes are in bold

zero = [0,0,0,0,0];

r1=[2:2:10];
r2=[3:3:15];
r3=[4:4:20];
r4=[5:5:25];
r5=[6:6:30];
i1=10;
i2=15;
i3=20;
A=[r1,r2,zero;r1,r4,r3;r2,r3,r5];
B=[i1-i2,i1-i3,0;i2-i1,i2,i2-i3;i3-i1,i3-i2,i3];
C=B*A;

Earlier you were using only 0 which is a scalar and not an array of size 5.

Now instead of single 0, the code is using an array of 5 zeroes: 'zero'

Thus will give you your desired answer