I have a row vector v of randomly generated numbers. I need to create a for-end statement using a looped variable, k, that will be assigned to every element of the row vector whose elements represent the positions of the row vector. I need to find the number of negative elements in the vector, number of positive elements, the sum of all elements, and the product range of all real numbers all within the for-end. I've started with naming and defining my variables, but I can't seem to figure out how to start the for-end statement.
MATLAB: For-end statements
for end
Related Solutions
neg_count = 0;pos_count = 0;pos_total = 0;range_prod = 1;for idx = 1 : length(v) if v(idx) is negative neg_count = neg_count + 1; end ... if v(idx) is in the particular range range_prod = range_prod * v(idx); endend
%Setting all original variables
Em=2.4e9;Ef=76e9;vm=0.34;vf_samll=0.22;theta=30;Vf=0:0.1:1;Ex = zeros(1, length(Vf));Ey = zeros(1, length(Vf));Gxy = zeros(1, length(Vf));vxy = zeros(1, length(Vf));c = 1;for ii = 1:length(Vf) Vm=1-Vf(ii); %Finding shear and bulk modulus'
Gm=Em/(2*(1+vm)); Gf=Ef/(2*(1+vf_samll)); Km=Em/(3*(1-2*vm)); Kf=Ef/(3*(1-2*vf_samll)); %Find k*,E1,v12,G12
k=(Km*(Kf+Gm)*Vm+Kf*(Km+Gm)*Vf(ii))/((Kf+Gm)*Vm+(Km+Gm)*Vf(ii)); E1=Em*Vm+Ef*Vf(ii); v12=vm*Vm+vf_samll*Vf(ii)+((vf_samll-vm)*((1/Km)-(1/Kf))*Vm*Vf(ii))/((Vm/Kf)+(Vf(ii)/Km)+(1/Gm)); G12=Gm+(Vf(ii)/((1/(Gf-Gm))+(Vm/(2*Gm)))); %Beta's, gamma's, alphas and roe
betam=1/(3-4*vm); betaf=1/(3-4*vf_samll); gamma=Gf/Gm; alpha=(betam-gamma*betaf)/(1+gamma*betaf); roe=(gamma+betam)/(gamma-1); %G23, E2 and v23
G23=Gm*(1+((1+betam)*Vf(ii))/(roe-(1+(3*betam^2*Vm^2)/(alpha*Vf(ii)^3+1))*Vf(ii))); E2=4/((1/G23)+(1/k)+(4*v12^2/E1)); v23=(E2/2*G23)-1; %Creating reduced lamina stiffness matrix
Z=(E1-v12^2*E2)/E1; Q11=E1/Z; Q22=E2/Z; Q12=v12*E2/Z; Q66=G12; Q=[Q11,Q12,0;Q12,Q22,0;0,0,Q66]; %Transformation matrices
n=sind(theta); m=cosd(theta); q11=Q11*m^4+Q22*n^4+2*m^2*n^2*(Q12+2*Q66); q12=m^2*n^2*(Q11+Q22-4*Q66)+(m^4+n^4)*Q12; q16=(Q11*m^2-Q22*n^2-(Q12+2*Q66)*(m^2-n^2))*m*n; q22=Q11*n^4+Q22*m^4+2*m^2*n^2*(Q12+2*Q66); q26=(Q11*n^2-Q22*m^2+(Q12+2*Q66)*(m^2-n^2))*m*n; q66=(Q11+Q22+Q12*2)*m^2*n^2+Q66*((m^2-n^2)^2); q=[q11,q12,q16;q12,q22,q26;q16,q26,q66]; %Finally calculating the laminate properties
Ex(c)=q11-q12^2/q22; Ey(c)=q22-q12^2/q11; Gxy(c)=q66; vxy(c)=q12/q22; c =c+1;endplot(Vf, Ex, Vf, Ey, Vf, Gxy, Vf, vxy);grid on , legend({'Ex', 'Ey', 'Gxy', 'vxy'})
Best Answer