필터 지우기
필터 지우기

Matrix dimensions must agree.

조회 수: 1 (최근 30일)
mohamed saber
mohamed saber 2012년 3월 28일
where is the error please ???
clear,clc
cp=1005;
r=287;
d=1.2;
v=300;
tx=284;
px=98;
to=298;
py=100:200;
a1=((d*v*r).^2)./(2*cp.*py);
a2=1;
a3=-to;
p=[a1 a2 a3];
ty=roots(p);
ds=(cp.*log(ty./tx))-(r.*log(py./px));

답변 (4개)

Sean de Wolski
Sean de Wolski 2012년 3월 28일
Error using - Matrix dimensions must agree. That is an error with '-' (minus). Going to the only minus:
Compare sizes:
(r.*log(py./px))
and
(cp.*log(ty./tx))
There is your problem.
  댓글 수: 1
mohamed saber
mohamed saber 2012년 3월 28일
what should i do ???

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2012년 3월 28일
roots() returns a column vector, but everything else is a row vector.
Your a1 vector is the same length as py, but when you put a2 and a3 on the end of that, your p vector becomes 2 elements longer than py. roots() returns a vector one element shorter than its input vector, so roots() is going to return a vector one element longer than py. You then try to subtract between that vector of length of py + 1 and the vector of length of py.
  댓글 수: 2
mohamed saber
mohamed saber 2012년 3월 28일
what about that ??
clear,clc
cp=1005;
r=287;
d=1.2;
v=300;
tx=284;
px=98;
to=298;
py=100:200;
a1=((d*v*r).^2)./(2*cp.*py);
a2=1;
a3=-to;
p=[a1 a2 a3];
ty=roots(p);
Ty=ty(1:end-1);
ds=(cp.*log(Ty./tx))-(r.*log(py./px));
Walter Roberson
Walter Roberson 2012년 3월 28일
Ty=ty(1:end-1) .';
in order to get the row vector you need.

댓글을 달려면 로그인하십시오.


mohamed saber
mohamed saber 2012년 3월 29일
could you please write the syntax ???

Andrei Bobrov
Andrei Bobrov 2012년 3월 29일
cp=1005;
r=287;
d=1.2;
v=300;
tx=284;
px=98;
to=298;
py=(100:200).';
a1=((d*v*r).^2)./(2*cp.*py);
a2=1;
a3=-to;
p=[a1; a2; a3];
ty=roots(p);
Ty=ty(1:end-1);
ds=(cp.*log(Ty./tx))-(r.*log(py./px));

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by