Inner matrix dimensions problem

Hi, I'm trying to execute the following code:
%------------ % Define mesh grid
[x, t] = meshgrid([0:.5:10],[1:.5:10]);
% n is the number of iterations of a Fourier sum
n = 100;
i = 1;
% q is the total of all the summed z's
q = 0;
while i < (n+1)
z = ((2*pi)/(3*i^3))*(1-cos(i*pi))*sin(i.*x)*(exp(-3*(i^2).*t) + 2*cosh(2*(i^2).*t));
q = z + q;
i = i + 1;
end
% plot of q v.s. x and t% surf(x,t,q) mesh(x,t,q) contour(x,t,q)
And I keep getting the error ???=====> mtimes which I'm told is because matrix dimensions don't agree. Can't see where else I need to put '.'. Could anybody help?
Thanks

 採用された回答

Matt Fig
Matt Fig 2011 年 3 月 25 日

0 投票

You were close, only missing one dot.
z = ((2*pi)./(3*i^3))*(1-cos(i*pi))*sin(i.*x).*(exp(-3*(i^2).*t) + 2*cosh(2*(i^2).*t));

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 3 月 25 日

1 投票

vectorize('z = ((2*pi)/(3*i^3))*(1-cos(i*pi))*sin(i.*x)*(exp(-3*(i^2).*t) + 2*cosh(2*(i^2).*t));')
ans =
z = ((2.*pi)./(3.*i.^3)).*(1-cos(i.*pi)).*sin(i.*x).*(exp(-3.*(i.^2).*t) + 2.*cosh(2.*(i.^2).*t));

1 件のコメント

Matt Fig
Matt Fig 2011 年 3 月 25 日
+1 Now that's an easy way to avoid this type of problem!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by