what is the error Matrix dimensions must agree.?

1 回表示 (過去 30 日間)
HADIMARGO
HADIMARGO 2018 年 12 月 16 日
編集済み: James Tursa 2018 年 12 月 18 日
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 月 18 日
Please do not close questions that have an answer.

サインインしてコメントする。

回答 (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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by