Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
error: index must be a positive integer or logical -- create movie --SOLVED
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
EDITED--> SOLVED
Hello, i have this matlab code and it gives me the error i have in title.
% solution of the scalar wave 1d equation
time=1000;
steps=1000;
a=input('Please enter the value of the ratio cdt/dx :');
%preallocate matrix u
u=zeros(steps,time);
%fill matrix u
for i=1:time-1
for j=1:steps-1
if (i==1)
u(j,i)=0; EDIT--> u(j,i)=1;% initial condition
else EDIT --> j==1 becomes j==2
if (j==*2* && i>=*2* && i<=50) % 50 is the time step for the pulse
u(j,i)=50;
else
%solution of wave equation
u(j,i+1)=a*a*(u(j+1,i)-2*u(j,i)+u(j-1,i))+2*u(j,i)-u(j,i-1);-->here is the error
end
end
end
end
for k=1:steps EDIT-->> if mod(i,100)==0
figure(i/100)
plot(u(:,i+1))
plot(u(k,1:100))
plot(u(k,1:200))
plot(u(k,1:300))
plot(u(k,1:400))
plot(u(k,1:500))
plot(u(k,1:600))
plot(u(k,1:700))
plot(u(k,1:800))
plot(u(k,1:900))
plot(u(k,1:999))
end
Also ,how can i write more efficiently the last loop (with the plots) and how can i create a movie in this example? Thank you.
EDITED-->>SOLVED
0 comentarios
Respuestas (1)
Sean de Wolski
el 29 de Mzo. de 2011
It's right here:
u(j-1,i))
j = 1; and thus j-1 = 0 which is not a valid index.
to plot more effectively
hold on
before the for-loop so the plots overlay.
1 comentario
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!