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

 Accepted Answer

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

More Answers (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 Comment

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

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!