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

 Risposta accettata

Matt Fig
Matt Fig il 25 Mar 2011
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));

Più risposte (1)

Sean de Wolski
Sean de Wolski il 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 Commento

Matt Fig
Matt Fig il 25 Mar 2011
+1 Now that's an easy way to avoid this type of problem!

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by