2015-05-24 101 views
0

虽然我关注下面的代码中的数组运算符,但我一直在得到一个矩阵维数的错误。由于我不愿意严格执行矩阵运算,有人可以解释尺寸/尺寸问题的起源吗? 。函数句柄和数组运算符 - Matlab

由于使用

错误*矩阵尺寸必须同意

% integrand behaviour 
[email protected](k) k .* exp(-k); 
x=0.5; 
al=1; 
bet=0.89; 
theta0=(1/al) .*atan(bet .*tan(pi*al/2)); 
c=exp(-(pi .* x) ./2 * bet); 
c2=1 /(2.*abs(bet)); 
[email protected](theta) 2/pi .* ((pi/2 + bet.*theta)/cos(theta)) .* exp(1/bet .* (pi/2 + 
bet.*theta)... 
.* tan(theta)); 
[email protected](theta) c .* v1(theta); 
[email protected](theta) f(g(theta)) ;  % values of integrand 
a=[-pi/2:0.2:pi/2]'; 
Y=y(a); 
plot(a,Y) 

回答

1

你的问题的根源就在这里:

(pi/2 + bet.*theta)/cos(theta) 

您使用/运算符,其中我认为你的意思是使用./个操作员。

+0

这并不重要。我刚刚意识到问题的根源在于列向量'a'。实际上,代码适用于任何标量(例如a = pi/6等),因此解决方案就是使它在矢量上工作,就我而言。 – owner

+0

它确实很重要。事实上,你的'a'是一个16元素的列向量。我突出显示的这条线将变成一个16x16的矩阵,这显然是错误的。请记住,'/'是一个矩阵运算符,而'。/'是元素明智的。 –

+0

非常感谢您的及时反馈,因为我绝对错过**。/ cos(theta)**。你是对的。干杯 – owner