Keep getting the "Array indices must be positive integers or logical values." error
Mostrar comentarios más antiguos
Trying to simulate a water rocket using matlab, however I can't get my for loop to work properly.
This is what I have so far:
close all
clear all
P0 = 6e5; %Pa
Pout = 1e5; %Pa
V0 = 2; %l
V = 1.5; %l
gamma = 1.4;
rho_w = 998; %kg/m^3
%Pin = P0*(V/V0).^-gamma;
dt = 0.01;
t = 1:dt:100;
Ve(1) = 0; %m/s
Pin(1) = 6e5; %Pa
v0 = 0; %m/s
v = 0; %m/s
M0 = 0.1; %kg
M = M0 + (V0-V)*rho_w;
for i = 1:100
Pin(i+1) = Pin(i) - P0(V/V0).^-gamma;
Ve(i+1) = sqrt(2*(Pin(i) - P0)/rho_w);
%v = Ve*log(M0/M) + v0;
end
Really hoping one of you can enlighten me, because I'm completely lost here.
3 comentarios
Guillaume
el 12 de Dic. de 2018
"however I can't get my for loop to work properly"
Rather than leaving it up to us to guess what the problem is. What don't you tell us? If you get an error, give us the full text of the error message. If you don't get the result you expected tell us what result you get and what you expected instead (and why).
The only comments in your code are just to indicate units. There is no comment explaining at all what the code is supposed to be doing or what the variables represent.
Certainly one puzzling thing is that P0(V/V0). What is that supposed to do ? (what it does is try to index the P0 array with the invalid index V/V0 = 0/0 = NaN)
Image Analyst
el 12 de Dic. de 2018
V/V0 = 1.5/2, not 0/0
madhan's Answer below lets the code run without error. No guarantee about the equations correctness though - I didn't try to verify them.
Guillaume
el 12 de Dic. de 2018
Oh! I didn't see that there were both V and V0 variables (uppercase) as well as v and v0 (lowercase).
That's really begging for trouble! You can be sure at some point the wrong case will be used. Never distinguish variable names just by casing.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!