Error using * matrix dimensions must agree?
이전 댓글 표시
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
David Goodmanson
2016년 10월 2일
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 ?
채택된 답변
추가 답변 (1개)
Jang geun Choi
2016년 10월 2일
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'))
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!