Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Help with while loop as it failed as left and right sides have different number of elements.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to work out the velocity of a falling object at 100km above earth. I have inputted initial height as 150km, initial v = 0, and initial t=0. Acceleration (a) in this case is equal to (40x10^7)/(6371+h)^2 Height = is 150k-(0.5*a*t^2). V=a*t loop counter (i) =1 Time step (dt)=0.005
My code is:
>> h(1)=150000;
>> dt=0.005;
>> t(1)=0;
>> v(1)=0;
>> a=(40*10^7)/(6371+h)^2;
>> h=150000-(0.5*a*t^2);
g=(40*10^7)/(6371+h)^2;
v=a*t;
>> while h>=100000
t(i+1)=t(i)+dt;
h(i+1)=150000-(0.5*a*t(i+1)^2);
a(i+1)=(40*10^7)/(6371+h(i+1))^2;
v(i+1)=a(i+1)*t(i+1);
i=i+1;
end
The goal of this loop is to get a value for v with a non constant acceleration that changes with h.
When I do this I get an error saying that the left and right sides have different number of elements. I also think that I need to do something with the differential equations or maybe use the F=ma as I know the mass of the object to be 850kg. I am knew to matlab and dont really know what im doing so any help would be appreciated.
2 comentarios
Walter Roberson
el 8 de Mzo. de 2020
Please post actual code. MATLAB does not use While it uses while and 100km is invalid syntax
Respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!