Effacer les filtres
Effacer les filtres

what is the error Matrix dimensions must agree.?

2 vues (au cours des 30 derniers jours)
HADIMARGO
HADIMARGO le 16 Déc 2018
Modifié(e) : James Tursa le 18 Déc 2018
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 commentaire
Walter Roberson
Walter Roberson le 18 Déc 2018
Please do not close questions that have an answer.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 16 Déc 2018
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 ?

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by