what is the error Matrix dimensions must agree.?
조회 수: 1 (최근 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
답변 (1개)
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 ?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!