Home > Software engineering >  How perform Kinetic energy summation in matlab, between matrixs and vector
How perform Kinetic energy summation in matlab, between matrixs and vector

Time:11-07

Formula

%% Popolazione di detriti

% Costanti
Mv=10000; % 10000 kg massa nominale velivolo
V_0 = 200*.3048; % velocità al distacco dalla WKT in m/s a 14325 m

N=1000
D=rand(N,1); % vettore debris di 100 numeri casuali tra 0 e 1
somma=sum(D); 
m_i=(D/somma)*Mv; %mass casuale dei detriti
ver=sum(m_i); % verifica che la somma dei dei 100 pezzi razionalizzati restituisce il peso del velivolo

vx_i = randn(N,1); % componenti random di velocità nelle tre direzioni
vy_i = randn(N,1); 
vz_i= randn(N,1);
DeltaV_iStar= [vx_i,vy_i,vz_i]; % matrix velocity i-esima debris
    %% Momentum
DeltaQ_err=zeros(1,3);
DeltaQ=zeros(N,3); %inizializzo matrice 
for k=1:N
    DeltaQ(k,:)=(m_i(k)*DeltaV_iStar(k,:));  
    DeltaQ_err=DeltaQ_err DeltaQ(k,:);
end
DeltaQ_err


DeltaV_err = DeltaQ_err/Mv ; % errore da togliere agli incrementi iniziali
DeltaV_c = DeltaV_iStar-DeltaV_err;

DeltaQ_err2=zeros(1,3);
DeltaQ=zeros(N,3); %inizializzo matrice 
for k=1:N
  DeltaQ(k,:)=(m_i(k)*DeltaV_c(k,:));  
  DeltaQ_err2=DeltaQ_err2 DeltaQ(k,:);
end
DeltaQ_err2


%% Kinetic Energy
V_element= randn(3,1); % componenti della velocità iniziale
B = V_element/norm(V_element) 
v=V_0*B
vlength= norm(v);

prodotto=0;
Ek_d=0;
for k=1:N 
    prodotto(k,:)=.5*[m_i(k)*(v(k) DeltaV_c(k,:)).^2];
    Ek_d=Ek_d prodotto(k,:);
end
Ek_d

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-3.

Error in Debris_Footprint (line 59) prodotto(k,:)=.5*[m_i(k)*(v(k) DeltaV_c(k,:)).^2];

I tried with a for loop but the result I get is a vector. the problem is that kinetic energy is NOT a vector quantity. In my code: m is m_i V0 = v DeltaVc = DeltaV_c. I upload the entire code for a better understanding. It's for a university project. The first part of the code is right according to my pofessor. I need help with the kinetic energy part

CodePudding user response:

the total kinetic energy of a body is the sum of its kinetic energy in each direction, so we just loop over the 3 directions and get the kinetic energy in each direction and sum them for each particle.

prodotto=0;
Ek_d=0;
for k=1:N
    for direction = 1:3
    prodotto = .5*m_i(k)*(v(direction) DeltaV_c(k,direction)).^2;
    Ek_d=Ek_d prodotto;
    end
end
Ek_d

this can be written more efficiently, but this form best explains the operation.

CodePudding user response:

what you want to do and what is m and v0 and delta vc.

let's say m is matrix and v is velocity matrix. write like this :

sum =0;
for i=1:N
   sum = (1/2)* m.*((v vc).*(v vc)) sum;
end

in this way you can get final sum value.

  • Related