Error using * matrix dimensions must agree?
Show older comments
Please note that I have tried using " .* " instead of " * " and it STILL doesn't work. That is the fix that every single similar question has gotten. Afterwards, it just says MATRIX dimensions must agree instead of INNER MATRIX dimensions must agree. Below is my script:
g = 9.81; t = [15:15:75]; x = [0:5:80]; v = 28; yo = 0;
y = (tan(t))*x - (g/(2*v^2*(cos(t))^2))*x^2 + yo;
It is supposed to generate results that are assembled in an array where the first dimension (rows) corresponds to the x values, and the second dimension (columns) corresponds to the t values. What should I go about doing in order to fix this error of matrix dimensions?
2 Comments
David Goodmanson
on 2 Oct 2016
the 'meshgrid' function is designed to give you the x and t arrays that you need.
"That is the fix that every single similar question has gotten"
It is not a "fix". The users were using the wrong operator for their algorithm, that is all, and someone told them which operator to use.
It usually boils down to people not knowing about different matrix multiplication methods, not really understanding how they can be used, and not bothering to read the documentation. No matrix multiplication method is a "fix" for another matrix multiplication, they simply do different things. Is log2 a "fix" for log10 ?
Accepted Answer
More Answers (1)
Jang geun Choi
on 2 Oct 2016
I think, if your 'y' is vary with two independent variables, x and t, you should make not one dimensional vector domain but two dimensional matrix domain.
In order to make the matrix domain, you can use 'meshgrid' function.
g=9.81;
t=[15:15:75];
x=[0:5:80];
v=28;
yo=0;
[xm,tm]=meshgrid(x,t);
y=(tan(tm)).*xm-(g./(2.*v^2.*(cos(tm)).^2)).*xm.^2+yo;
pl=plot(x,y);
legend(pl,num2str(t','t=%2.0f'))
Categories
Find more on Creating and Concatenating Matrices 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!