Home > front end >  How perform a Subtraction between matrix Matlab. Aerospace
How perform a Subtraction between matrix Matlab. Aerospace

Time:11-06

Hi i need to perform in matlab a subtraction between a matrix and a row vector. I am working on a university project in which we assume an airplane explosion resulting in the generation of debris. for conservation of momentum, momentum must remain the same after the explosion. Being that I generate the debris and its velocity increments randomly, there is an error in momentum , which I am trying to remove. The result I get is close to zero. But for physics , it has to be zero. I think I am doing some steps wrong in the operations between matrices and vectors

Mv=10000; 
V_0 = 200*.3048; 

N=1000
D=rand(N,1); 
somma=sum(D); 
m_i=(D/somma)*Mv; %mass of debris
ver=sum(m_i); 

vx_i = randn(N,1);
vy_i = randn(N,1); 
vz_i= randn(N,1);

DeltaV_iStar= [vx_i,vy_i,vz_i]; % i-esima velocity matrix 



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 % momentun 


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

**DeltaV_c(:,3) = DeltaV_iStar(:,3) - DeltaV_err(1);** %i-esima matrix velocity which has been corrected

%% Now i do the same thing but with the correct value of velocity to verify that the momentum is zero

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 % momentum that must be zero










CodePudding user response:

There is only condtion in the matrix subtraction, dimension must match. lets say a(n,m) and b(n,m); then you can directly write in matlab like: a-b; you will get result.

  • Related