why am i facing this error in plotting ?

4 Ansichten (letzte 30 Tage)
guetty abboud
guetty abboud am 16 Dez. 2017
Beantwortet: Star Strider am 16 Dez. 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')

Antworten (1)

Star Strider
Star Strider am 16 Dez. 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')

Kategorien

Mehr zu Just for fun finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by