matlab - Converting to for loop -


how can convert code loop if add more forces , moments? lot code , computing unit vector , finding sum of forces in x direction, y direction , z direction , doing same moments.

this 1 particular case want put in loop when new forces applied accounted for.

any or nudge in right direction huge help! in advance.

load ('inputdata.mat')  a= zeros(6,6); b= zeros (6,1);   % calculate force in x,y,z direction, sums them , puts them in b  % vector positions 1,2,3   nf1=((forcedir(1,2))^2+(forcedir(1,3))^2+(forcedir(1,4))^2)^(1/2);  f1i=(forcedir(1,2)/nf1)* forcedir(1,1);  f1j=(forcedir(1,3)/nf1)* forcedir(1,1);  f1k=(forcedir(1,4)/nf1)*forcedir(1,1);  nf2= ((forcedir(2,2))^2+(forcedir(2,3))^2+(forcedir(2,4))^2)^(1/2);  f2i=(forcedir(2,2)/nf2)* forcedir(2,1);  f2j=(forcedir(2,3)/nf2)* forcedir(2,1);  f2k=(forcedir(2,4)/nf2)* forcedir(2,1);  b(1,1)= f1i+f2i; %external force in x  b(2,1)= f1j+f2j; %external force in y  b(3,1)= f1k+f2k; %external force in z  % calculate moments in x,y,z direction , puts them in b vector  % position 3,4,5  unitvectorforce1=[f1i f1j f1k];  momentbyforce1= cross(forcecoor(1,:),unitvectorforce1);  unitvectorforce2= [f2i f2j f2k];  momentbyforce2= cross(forcecoor(2,:),unitvectorforce2);  momentnormal=((dirmoment(1,2))^2+(dirmoment(1,3))^2+(dirmoment(1,4))^2)^(1/2);  m1i= (dirmoment(1,2)/momentnormal)*dirmoment(1,1);  m1j= (dirmoment(1,3)/momentnormal)*dirmoment (1,1);  m1k= (dirmoment(1,4)/momentnormal)*dirmoment(1,1);  unitvectormoment= [m1i m1j m1k];  b(4,1)= momentbyforce1(1)+momentbyforce2(1)+ unitvectormoment(1)  b(5,1)= momentbyforce1(2)+momentbyforce2(2)+ unitvectormoment(2)  b(6,1)= momentbyforce1(3)+momentbyforce2(3)+ unitvectormoment(3) 

if understand correclty, should trick:

for ii = 1:n   nf(ii) = ((forcedir(ii,2))^2+(forcedir(ii,3))^2+(forcedir(ii,4))^2)^(1/2);   fi(ii) = forcedir(ii,2) / nf(ii) * forcedir(ii,1);   fj(ii) = forcedir(ii,3) / nf(ii) * forcedir(ii,1);   fk(ii) = forcedir(ii,4) / nf(ii) * forcedir(ii,1);   %% etc end 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -