Saving maximum values from last iteration.

7 vues (au cours des 30 derniers jours)
Daniel J
Daniel J le 30 Mar 2024
Commenté : Daniel J le 31 Mar 2024
Hi, I want to save maximum values from last iteration for every "ii". If i run code for a single "ii" it saves up the data properly, but when I run it in range from 1 to 10 it just saves the first one. What am I missing?
*Edited code as asked.
d = 2;
v=700;
om = 500;
dp=5;
dC=20;
m = 1;
S = pi * ((d^2) / 4);
r = 1.500;
g=8;
dt = 1e-5;
i = 1;
t(i) = 0;
t0 = 0;
max_values=zeros(10,3);
v0=zeros(1,10);
numb = [ 0 0 0 0;1 1 1 1; 2 2 2 2;3 3 3 3;4 4 4 4;5 5 5 5;6 6 6 6;7 7 7 7;8 8 8 8;9 9 9 9];
for ii = 1:10
x(i)=numb(ii,1);
y(i)=numb(ii,2);
z(i)=numb(ii,3);
v0(ii) = om * numb(ii,4) * 2 * pi;
data = [0 0 300 240 180 120 60 0 330 300];
if ii==1
vz(i) = v;
vy(i) = 0;
vx(i) = 0;
elseif ii>1 && ii<=7
vz(i) = v;
vy(i) = -v0(ii)*cosd(data(ii));
vx(i) = v0(ii)*cosd(90-data(ii));
elseif ii>7 && ii<=10
vz(i) = v;
vy(i) = -v0(ii)*cosd(data(ii));
vx(i) = v0(ii)*cosd(90-data(ii));
end
while t < 500e-4
dvz(i) = (-1/(2*m))*r*S*v*vz(i);
dz(i) = vz(i);
vz(i+1) = vz(i) + dvz(i) * dt;
z(i+1) = z(i) + dz(i) * dt;
dvy(i) = (-1/(2*m))*r*S*v*vy(i)-g;
dy(i) = vy(i);
vy(i+1) = vy(i) + dvy(i) * dt;
y(i+1) = y(i) + dy(i) * dt;
dvx(i) = (-1/(2*m))*r*S*v*vx(i);
dx(i) = vx(i);
vx(i+1) = vx(i) + dvx(i) * dt;
x(i+1) = x(i) + dx(i) * dt;
t(i+1) = t(i) + dt;
i=i+1;
max_values(ii,1)=max(x(i));
max_values(ii,2)=max(y(i));
max_values(ii,3)=max(z(i));
end
end
  4 commentaires
Alexander
Alexander le 31 Mar 2024
So I think you are pleased now.
Daniel J
Daniel J le 31 Mar 2024
Sorry for late response, indeed now it works as inteded. Thank you so much and happy easter!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by