David
David

Reputation: 72

Matlab undefined 'matrix' errors

I need a hand with one matlab question it's been the bain of my thoughts for the past few days.

Ok. I have to produce a matrix respective to the horizontal vector T and the vertical vector V.

T = [40:10:-40];
V = [10:10:60]';

And implement the equation to fill the matrix/table

q = 35.74 + 0.6215*T - 35.75*v^0.16 + 0.4275*T^0.16

SO what I produced in matlab was

T = [40:10:-40];
V = [10:10:60]';
q = (35.74+(0.6215*T))-(35.75.*V.^0.16)+(0.4275.*T.*V.^0.16);

matrix((T,V)*q)

component q throws errors such as error using .* matrix dimensions must agree

and undefined function 'matrix' for input arguments of type 'double'

Would someone be able to throw me a lifeline here? any help much appreciated

Thanks

Upvotes: 1

Views: 102

Answers (2)

Divakar
Divakar

Reputation: 221664

Use meshgrid to map both T and V and then simply do element-wise operations -

T = [40:-10:-40]';
V = [10:10:60]';
[x,y] = meshgrid(T,V);
q = 35.74 + 0.6215.*x - 35.75.*y.^0.16 + 0.4275.*x.^0.16

I think this is what you were looking for, as I had to correct few errors too.

Upvotes: 2

Dan
Dan

Reputation: 45752

Many mistakes here,

firstly did you check to see if T and V look as you expect. Inspect them in the workspace. Firslty you'll find that T is empty! This is because you are trying to go from positive 40 to negative 40 by adding 10. So you should have been subtracting 10 and thus:

T = 40:-10:40;  

Note that you didn't need the [] and actually mlint would have told you that.

Secondly after you have correctly defined T as above you'll see that is has 9 elements whereas V has only 6. Now .* mean element-wise multiplication, i.e. you are telling matlab not to do matrix multiplication but rather to multiply each corresponding element of the two matrices. Naturally in order to do this the two matrices need to have the same dimensions and that is why you are getting a matrix dimensions must agree error. If you wanted actual matrix multiplication then it is T*V rather than T.*V

Lastly matrix((T,V)*q) is not Matlab syntax at all. I'm not really sure what you are trying to do here.

Upvotes: 1

Related Questions