For loop to find roots
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to find the roots of a function, with a parameter that changes. The function is that of a parabola
V=rand(10,1)
g=9.81
z0=500
I should use the following expression in for loop right?
t_roots=roots([-.5*g,V,z0])
0 commentaires
Réponses (1)
Askic V
le 6 Fév 2023
Yes, if V contains paramters, then the could would look like this:
V = rand(10,1);
g = 9.81;
z0 = 500;
for vi = 1: numel(V)
t_roots = roots([-0.5*g,vi,z0])
end
5 commentaires
Askic V
le 6 Fév 2023
I guess you are trying to achive something like this?
g=9.80665; %agravity
z0= 14325; %starting height
x0=0;
y0=0;
V_0=200*.3048; %starting velocity
gamma=0.78;
DeltaV_c = randn(10,3); %Speed increments in the three directions x, y, z
% Debris velocity components after the explosion
[r,c] = size(DeltaV_c);
for i = 1:r % each row contains increments in directions
V_0x=V_0*cos(gamma)+DeltaV_c(i,1);
V_0y=0+DeltaV_c(i,2);
V_0z=V_0*sin(gamma)+DeltaV_c(i,3);
%debris flight time
t_radici = roots([-.5*g,V_0z,z0]);
t = linspace(0,t_radici(t_radici>0),1000);
%distanza percorsa nelle tre direzioni
x=x0+V_0x*t;
y=y0+V_0y*t;
z=z0+V_0z*t-.5*g*t.^2;
plot3(x,y,z)
hold on
plot3(x0,y0,z0,'ro','MarkerSize',5)
plot3(x(end),y(end),z(end),'ro','MarkerSize',5)
xlabel('Posizione x (m)')
ylabel('Posizione y (m)')
zlabel('Posizione z (m)')
grid on
end
Voir également
Catégories
En savoir plus sur Calendar dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!