Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Index exceeds the number of elements (1)

1 visualización (últimos 30 días)
Advait Sinha
Advait Sinha el 18 de Jun. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
close all;
dt = 0.01;%time step
k1=1;
m=1;%initial parameters
u1 =2;
u2 =1;
v1=2;
a1=1;
tend=10;
t=0;
i=1
while t < tend-2*dt
v1h=v1(i)-dt*k1*u1(i)-u2(i)/ (2*m);
u1(i+1)= u1(i)+ dt*v1h;
a1(i+1)= -k1*u1(i+1)/2;
v1(i+1)= v1h + dt*a1(i+1)/2;
i = i+1;
t = t + dt
end
plot(linspace(0,tend,tend/dt),u1);

Respuestas (1)

Adam Danz
Adam Danz el 18 de Jun. de 2019
Editada: Adam Danz el 24 de Jun. de 2019
On the second iteration of your while-loop, u2(i) is causing the error since you're trying to access the second element of u2 but u2 will always be u2=1 and that never changes in your code. I see you're updating u1 within the while loop but that isn't happening for u2.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by