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

 采纳的回答

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 个)

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 个评论

+1 Now that's an easy way to avoid this type of problem!

请先登录,再进行评论。

类别

帮助中心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!

Translated by