Inner matrix dimensions problem
Show older comments
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
More Answers (1)
Sean de Wolski
on 25 Mar 2011
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
Matt Fig
on 25 Mar 2011
+1 Now that's an easy way to avoid this type of problem!
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!