why am i facing this error in plotting ?

8 vues (au cours des 30 derniers jours)
guetty abboud
guetty abboud le 16 Déc 2017
a=1;
CFL = 0.8;
tf = 4/3;% tmax = 4/3;
N=50;
x = linspace(-1,1,N);% i took x = [-5;5]
dx = 2 /(N-1);
dt = (CFL * dx)/ abs(a);
lambda = (dt/dx);
t = [-4/3 : tf];
%Initial conditions:
for i = 1: N
if abs(x(i)) < 1/3 %McS, wrong abs(x(i) < 1/3 )
u(i,1) = 1;
elseif abs(x(i)) > 1/3 & abs(x(i)) <= 1
u(i,1) = 0;
end
end
plot(x,u(:,1),'k')
the error is :
Error using *plot*
vectors must be the same length
Error in 'burger' (line20)
plot(x,u(:,1),'k')

Réponses (1)

Star Strider
Star Strider le 16 Déc 2017
Your code runs for me without error in R2017b.
One possibility is that since ‘x’ is a row vector and ‘u’ is a column vector, transposing ‘x’ to a column vector could solve your problem:
plot(x', u, 'k')

Catégories

En savoir plus sur Just for fun 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