what is the error Matrix dimensions must agree.?

2 次查看(过去 30 天)
code:
clc
clear all;
x=linspace(-10,10,1000);
t=0:1:20;
k=10;
l=10;
u_x=2*k*x/l.*(x>0 & x<l/2)+2*k*(1-x)/l.*(x>l/2 & x<l/2);
plot(x,u_x)
s=0;
for n=1:1:1000
s=s+(1/n.^2).*sin(n.*pi/2).*cos(n.*pi.*t/l).*sin(n.*pi.*x/l);
end
u_x_t=(8*k/pi^2)*s;
................................................
error:
Matrix dimensions must agree.
Error in Untitled (line 16)
s=s+(1/n.^2).*sin(n.*pi/2).*cos(n.*pi.*t/l).*sin(n.*pi.*x/l);

回答(1 个)

Walter Roberson
Walter Roberson 2018-12-16
t is length 21. cos n pi t over l will be length 21
x is length 1000. sin n pi x over l will be length 1000
you are trying to .* those two together . What is your expectations about the size of the results ?

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by