Q1)) x = randperm(35); y = x; for i = 1:length(x) if x(i)<6 y(i)=2; else x(i)<20 y(i)=x(i)-4; else x(i)<=35 y(i) = 36-x(i); end end x = randperm(35); y = 2 * (x<6); y = y + ((x>=6)&(x<20)).*(x-4); y = y + ((x>=20&(x<=35)).*(36-x); ------------------------------------------------- Q2)) x = 1:10 x = [1 2 3 4 5 6 7 8 9 10] y = [3 1 5 6 8 2 9 4 7 0] 1) (x>3)&(x<8) [0 0 0 1 1 1 1 1 1 1] & [1 1 1 1 1 1 1 0 0 0] [0 0 0 1 1 1 1 0 0 0] 2) x(x>5) x([0 0 0 0 0 1 1 1 1 1])= [6 7 8 9 10] Example: W = [1 5 -2 4 8 -3 0 1 7] W(W>=0)= [1 5 4 8 0 1 7] 3) y(x<=4) y([1 1 1 1 0 0 0 0 0 0]) = [3 1 5 6] 4) x((x<2)|(x>=8)) x([1 0 0 0 0 0 0 0 0 0]|[0 0 0 0 0 0 0 1 1 1]) x([1 0 0 0 0 0 0 1 1 1]) [1 8 9 10 ] 5) y((x<2)|(x>=8)) y([1 0 0 0 0 0 0 1 1 1]) [3 4 7 0] 6) x(y<0) x([0 0 0 0 0 0 0 0 0 0]) [] ------------------------------------------------------ Q3) x=-1 y=500 x=5 y=4*5=20 x=30 y=10*30=300 x=100 y=500 ------------------------------------------------------ Q4) T = input('Enter a value for T: '); if((T>0)&(T<100)) h = T-10; else if (T>100) h = 0.45*T+900; end ---------------------------------------------------- Q5) 1) sum(x) 2) y=[0 0 0 0 0 0]; s=0; for i = 1:length(x) s = s +x(i); y(i)=s; end 3) sin(x) --------------------------------------------------------- Q6) C = X.*Y; sum(C); s=0; for i=1:3 C(i) = X(i)*Y(i); s = s + C(i); end D = X./(2+X+Y); for i=1:3 D(i) = X(i)/(2+X(i)+Y(i)); end ---------------------------------------------------- Q7) 1) x+y = [3 5 13] 2) x'+y error 3) A-[x' y'] error 4) [x;y'] error 5) [x;y] = [1 4 8; 2 1 5] 6) A-3 = [0 -2 3; 2 -1 4]