Try-Exam 2015 Notice that the total points of this exam are 75 but it will be graded from 70 points. Making your answer clear and keeping your paper clean will be appreciated. Answer the following questions: Q1:[15 points] Q2:[15 points] a) The graph of the function = + + + + passes through the points (–4, –7.6), (–2, –17.2), (0.2, 9.2), (1, –1.6), and (4, –36.4). Determine the constants a, b, c, d, and e using a MATLAB program. b) Given the two following polynomials: (x-7)(x+5)(2x-3)(x+4)(x-6) and (3x-3)(x+2) Write MATLAB commands to add and multiply them. Q3:[15 points] Given the following data: Year 1750 1800 1850 1900 1950 1990 2000 2009 Population 791 980 1260 1650 2520 5270 6060 6800 a) Determine the exponential function that best fits the data. Use the function to estimate the population in 1980. Generate one figure window with two plots: the estimated exponential equation (with the data points with circles) and the data points using solid line. b) Estimate the population in 1975 with linear and spline interpolations. Page 1 of Q4:[15 points] The file Store.txt contains the data of 50 products in a factory. The data are arranged in rows and columns. Each row represents the following data for each product: product id, unit price, number of available units. Write a MATLAB program to: a) Display the total credit value (total price) of the products. b) Display the number of most expensive products (unit price >= 150). c) Plot the histogram of the number of available units. d) Export the following statistics to a text file with name Output.txt: the most expensive product and the product with smaller available amount. (id and value) Q5:[15 points] Mention briefly what the following program does. Mention its output for each of the following inputs: a) 2, 3, -19, 10, 20 b) -11, 17, 33, 5, 0 A=zeros(5,1); for i=1:5 A(i)=input('Enter an integer value: '); end c=1; pos=1; while (c<=5) y=A(c); for k=c:5 if(A(k)>=y) y=A(k); pos=k; end end temp=A(c); A(c)=A(pos); A(pos)=temp; fprintf('%i ',y) c=c+1; end Page 2 of 2 Model Answer Q1:[15 points] e='V=(1/3)*pi*h*(R1^2+(1.2*R1)^2+R1*(1.2*R1))'; R1=solve(e,R1); V=1000; h=8:2:16; R1=subs(R1,V); R1=subs(R1,h); R2=1.2*R1; S=pi*(R1+R2).*sqrt((R2-R1).^2+h.^2)+pi*(R1.^2+R2.^2); S=double(S); fprintf('\n The results are grouped as follows:\n') fprintf('\n R1 \t\t R2 \t\t S \n') fprintf('\n %6.3f \t %6.3f \t %6.3f ',R1,R2,S) Q2:[15 points] (a) xs=[-4;-2;0.2;1;4]; ys=[-7.6;-17.2;9.2;-1.6;-36.4]; coeff_a=xs.^4; coeff_b=xs.^3; coeff_c=xs.^2; coeff_d=xs; coeff_e=[1; 1; 1; 1; 1]; X=[coeff_a, coeff_b coeff_c, coeff_d, coeff_e]; C=inv(X)*ys Q2:[15 points] (b) sym x p1=(x-7)*(x+5)*(2*x-3)*(x+4)*(x-6); p2=(3*x-3)*(x+2); p1=expand(p1) p2=expand(p2) A=p1+p2 M=expand(p1*p2) Q3:[15 points] Year=[1750 1800 1850 1900 1950 1990 2000 2009]; Population=[791 980 1260 1650 2520 5270 6060 6800]; p=polyfit(Year,log(Population),1) m=p(1); b=exp(p(2)); %estimate the population at 1980 EP=b*exp(m*1980) %one figure for two plots x=Year; y=b.*exp(m*x); subplot(2,1,1) plot(Year,Population,'o',x,y) subplot(2,1,2) plot(Year,Population) % interpolations using linear and spline Ent_P1=interp1(Year, Population,1975,'linear') Ent_P2=interp1(Year, Population,1975,'spline') Q4:[15 points] S=load('Store.txt') Price=S(:,2) Units=S(:,3) % the total value of the products TV=Units.*Price; TV=sum(TV); fprintf('The total value is %8.3f\n',TV) % the number of most expensive products count=sum(Price>=150); fprintf('The total value is %i\n',count) %the histogram of the number of available units hist(Units); % to export the most expensive product and the product with smaller % available amount. ID=S(:,1); mx=max(Price) mx_index=find(Price==mx) mx_id=ID(mx_index) mn=min(Units) mn_index=find(Units==mn) mn_id=ID(mn_index) fid=fopen('Output.txt','w') fprintf(fid,'Most expensive item: id= %d \t price=%5.3f \n',mx_id,mx) fprintf(fid,'Less available item: id= %d \t units=%d \n',mn_id,mn) fclose(fid) ]Q5:[15 points أو :وم ا ر :ا رج ! ل 5أ داد اد ل ا و م وم ر م ر ن ر ز . : 20, 10, 3, 2, -19 a) 2, 3, -19, 10, 20 33, 17, 5, 0, -11 b) -11, 17, 33, 5, 0
© Copyright 2024