LAB: 5 POLYNOMIAL EVALUATIONS, ROOTS OF POLYNOMIAL, ARITHMETIC OPERATIONS ON POLYNOMIALS. AIM: To write a program using the concept of polynomials in SCILAB SOFTWARE REQUIRED: SCILAB COMMANDS USED: [Pl fill all the polynomial commands you use for executing the following Questions] QUESTION 1: Evaluate the value of the polynomial y=s2+4s+2 at s = -2, s = 4.5 and s = 2+4i. Answer : Step 1: For polynomials use the command p = poly([2,4,1],"s","coeff") Step 2: The polynomial s2 + 4s + 2 will be displayed. Step 3: Find the values of the polynomial for s = -2, 4.5, 2 + 4i by the command horner(p, -2), horner(p, 4.5), horner (p, 2 + 4*%i). Output: -->p = poly([2,4,1],"s","coeff") p = 2 + 4s + s2 -->horner(p, -2) ans =- 2. -->horner(p, 4.5) ans =40.25 -->horner (p, 2 + 4*%i) ans = - 2. + 32.i QUESTION 2: Find the roots of the polynomial s2+4s+9=0, s3+3s2+4s+1=0 Answer: Step 1: To find out the given polynomial use the above command and denote qw for the polynomial s2 + 4s + 9 = 0 and q for s3 + 3s2 - 4s + 1 = 0. Ex. q = poly([1,-4,3,1],"s","coeff") Step 2: To find the roots of the given polynomial, use the command roots(qw) and roots (q). Output: -->qw = poly([9,4,1],"s","coeff"); -->q = poly([1,-4,3,1],"s","coeff"); -->roots(q) ans = - 4.0489173 0.6920215 0.3568959 -->roots(qw) ans = - 2. + 2.236068i - 2. - 2.236068i QUESTION 3: Find the roots of the Polynomial s4+3s3-15s2-2s+9=0. Answer: Step : Enter the polynomial command to find out the given polynomial and denote it by q. Use the root command (i.e.root(q)) to find out its roots. Output: -->q = poly([9,-2,-15,3,1],"s","coeff"); -->roots(q) ans = - 5.5745065 2.5836011 - 0.7950666 0.7859721 QUESTION 4: Add and subtract the two polynomials, i) a=(s2+8s+3) and b=(s2+2). ii) c=(8s3+6s2+5s+10) and d= (s3+2) Answer: Step 1: Enter the polynomial command to find out the given polynomials a and b and c and d. Step 2: To add and substract use the commands addition operator (a + b),(c+d) and substraction operator (a - b),(c-d). Result: (i) -->a = poly([3,8,1],"s","coeff"); -->b = poly([2,0,1],"s","coeff"); -->a+b ans = 5 + 8s + 2s2 -->a-b ans = 1 + 8s (ii) -->c = poly([10,5,6,8],"s","coeff"); -->d = poly([2,0,0,1],"s","coeff"); -->c+d ans = 12 + 5s + 6s2+ 9s3 ->c-d ans = 8 + 5s + 6s2 + 7s3 QUESTION 5: Evaluate the product of two polynomials i) (s3+4s2+5s+1) and (s2+2s+1). ii) (s+3),(s+6) and (s+2). Answer: (i) Step: Enter the polynomial command to find out the given polynomials a = s3 + 4s2 + 5s + 1 and b = s2 + 2s + 1 and use the multiplication operator (c*d) for the desired result. (ii) Step : Enter the polynomial command to find out the given polynomials. Denote them by p,q and r.{Ex. p = poly([3,1],"s","coeff")}. Result: (i) -->a = poly([1,5,4,1],"s","coeff"); -->b = poly([1,2,1],"s","coeff"); -->a*b ans = 1 + 7s + 15s2 + 14s3 + 6s4 + s5 (ii) -->p = poly([3,1],"s","coeff"); -->q = poly([6,1],"s","coeff"); -->r = poly([2,1],"s","coeff"); -->p*q*r ans = 36 + 36s + 11s2 + s3 QUESTION 6: Divide the polynomial P by Q where P=s3+4s+10 and Q=s3+3s2+4s+2. Answer: Step : Enter the polynomial command to find out the given polynomials P = s3 + 4s + 10 and Q = s3 + 3s2 + 4s + 2 and use the division operator (P/Q) for the desired result. Result: -->q = poly([2,4,3,1],"s","coeff"); -->p = poly([10,4,0,1],"s","coeff"); -->p/q ans = 10 + 4s + s3 --------------2 + 4s + 3s2 + s3 QUESTION 7: i) Determine the polynomial with roots = -2, 4 and 6. ii) Determine the polynomial whose roots are (-0.5 +0.866i) and (-0.5 -0.866i). Answer: (i)Step : To find the polynomial from its roots, use the command p = poly([-2,4,6],"s","roots") where -2,4,6 are the roots. (ii)Step : To find the polynomial from its roots, use the command p = poly([-0.5+ 0.866*%i,-0.5 0.866*%i],"s","roots") where -0.5+ 0.866i and -0.5 - 0.866i are the roots. Result: (i)p = 48 + 4s - 8s2 + s3 (ii) p =0.999956 + s + s2 QUESTION 1 2 0 A= 0 2 3 1 2 4 8: Determine the characteristic equation of the matrix A. Answer: Step 1 : First evaluate the given matrix by the matrix command A = [1 2 0; 0 2 3; 1 2 4] Step 2 : To find the characteristic equation of the polynomial with eigen value K, use the command poly charPoly Step 3 : So the command charPoly = poly(A,"K") gives the characteristic equation of the polynomial with the Eigen Value K. Result: - 8 + 8K - 7K2 + K 3 QUESTION 9: Evaluate the derivative and integral of the polynomial p(s) =s4+4s3+10s2+20s+15. Assume the constant of integration to be 1. Answer: To find the derivative: Step 1: Enter the polynomial command to find out the given polynomial s4 + 4s3 + 10s2 + 20s + 15 and denote it by q. Step 2: pd=derivat(q) gives the derivative of the polynomial as pd = 4s3 - 13s2 + 20s + 20. To find the integration: QUESTION 10: Find a polynomial of degree 3 to fit the following data: Answer: Step : The function reglin fits polynomials of degree 3. X 2 5 7 9 Y 24 156 384 500 For example, The slope of the line is given by m = c(1) and the y-intercept is given by b = c(2). The Linear fit is y = mx + b (matlab): c = polyfit([1 2 3],[2 4 8],1) returns 3.0000 -1.3333 and the equation stands as y = 3x 1.3333 (scilab): [m b] = reglin([1 2 3],[2 4 8],1) returns b = -1.3333333,m = 3.0000 So, for a polynomial of degree 3, the fit is y = x3 + ax2 + bx + c. The command for the polynomial is [a b c] = reglin([ 2 5 7 9 ],[ 24 156 384 500 ],3). Result: c = 34.185858 b = - 141.98131 a = 70.953271 RESULT: The programs were written in SCILAB using commands related to polynomials and were executed successfully. EXPT NO: 6 DATE:1/04/2015 TITLE: IMPLEMENTATION OF INPUT OUTPUT FUNCTIONS AIM: To study various input output functions using SCILAB. SOFTWARE REQUIRED: SCILAB QUESTION 1: Write a program to illustrate the use of keyboard command PROGRAM : clc; clear all; close all; a = eye(5); for j= 1:5, disp(j); if j ==3 keyboard; end; end; OUTPUT: 1 2 k>> >>return QUESTION 2: Write a program to illustrate the use of keyboard command to check the intermediate results and to add new data. Z PROGRAM: a=10; b=16; x=a+b; y=x/2; keyboard ans=y-3+9 OUTPUT: ans = 14 QUESTION 3: Illustrate the use of menu function, to choose a particular size from three different given sizes i.e., Large, Medium, Small PROGRAM: clc; clear all; close all; i=menu('choose a size' ,'large' , 'medium', 'small') OUTPUT: QUESTION 4: Using menu function, Select a candidate of your choice from the given choices, i.e., Kiran, Roshan, Surinder, John, Alka, Umesh, Abha and Neha PROGRAM: choice=menu('select student','Kiran','Roshan','Surinder','John' ,’Alka’,’Umesh’,’Abha’,’Neha’); disp(choice); OUTPUT: QUESTION 5: Write a program to illustrate the use of pause command. PROGRAM: p=[1 2;3 4]; q=[5 6;7 8]; disp('the matrix p is given as:'); disp(p); disp('program is paused,press any key to display q'); pause disp('the matrix q is given as :'); disp(q); z=p+q; disp('program is paused,press any key to display sum'); pause disp(z); OUTPUT: the matrix p is given as: 1 2 3 4 program is paused,press any key to display q the matrix q is given as : 5 6 7 8 program is paused,press any key to display sum 6 8 10 12 QUESTION 6: Illustrate the use of fprintf function to varying display the values of x varying from 0 to 180 with four equal intervals and also display its sine values. PROGRAM: x=0:45:180; y=[x;sin(x)]; disp(y); fprintf('%6.2f%6.4f\n',y); OUTPUT: 0.0 0.0000 45.00 0.7071 90.00 1.0000 135.00 0.7071 180.00 0.0000 QUESTION 7: Suppose x has five uniformly distributed values between 0 and 2. Represent the values of x in the following formats (fid =0, that is, standard screen Output’s): (a) Default format (b) Floating point format with width 6 and precision 3 and newline (c) Floating point format with zero padding and newline (d) Signed values and newline (e) Exponential format and newline (f) Compact format and newline PROGRAM: clc; clear all; close all; x=0:0.4:2; disp(x); fprintf('%6.3f\n',x); fprintf('%0.6.3f\n',x); fprintf('%16.3f\n',x); fprintf('%6.3\n',x); fprintf('%g\n',x); OUTPUT: 0 0.4000 0.8000 1.2000 1.6000 2.0000 0.000 0.400 0.800 1.200 1.600 2.000 0.000 0.400 0.800 1.200 1.600 2.000 0 0.4 0.8 1.2 1.6 2 QUESTION 8: Display the following statement as formatted output using format command: ‘The largest 3 digit no. is: 999’: PROGRAM: clc; clear all; close all; fprintf('the largest 3 digit number.is%f\n',999); OUTPUT: the largest 3 digit number is 999 QUESTION 9: Illustrate use of fscanf to read a file test.txt having first ten integer numbers in (a) (2 X 5) array format (b) One column (c) (5 X 2) array format PROGRAM: clc; clear all; close all; fid=fopen('text.txt','r') [a,count1]=fscanf(fid,'%f',[2,5]); fid=fopen('text.txt','r'); [a,count2]=fscanf(fid,'%f'); fid=fopen('text.txt','r'); [a,count3]=fscanf(fid,'%f',[5,2]); OUTPUT: a= 1 3 5 7 9 2 4 6 count1 = 10 8 10 a= 1 2 3 4 5 6 7 8 9 10 count2= 10 a= 1 6 2 7 3 8 4 9 5 10 count3 = 10 QUESTION 10: llustrate the use of fwrite function for writing binary data of different formats to a file named check.txt. PROGRAM: clc; clear all ; close all; a=[2 4 6 ; 3 5 7]; b=105; c='today is world cup final' fid=fopen('check.txt','w') x=fwrite (fid,a,'double') y=fwrite (fid,b,'short') z=fwrite (fid,c,'char') fclose(fid) OUTPUT: c= today is world cup final fid = 3 x= 6 y= 1 z= 24 ans = 0 QUESTION 11: PROGRAM: clc; clear all ; close all; fid1 =fopen('check.txt','r') [A, count1]=fread(fid1,[2,3],'double') [B,count2]=fread(fid1,[1],'short') [c,count3]=fread(fid1,[24],'char') c=c'; c=setstr(c) fclose(fid1) OUTPUT: fid1 = 3 A= 2 3 4 5 count1 = 6 B= 105 count2 = 1 c= 116 111 100 97 121 32 105 115 32 119 111 114 108 6 7 100 32 99 117 112 32 102 105 110 97 108 count3 = 24 c= today is world cup final ans = 0 QUESTION 12: Write a program to generate first five odd numbers and illustrate the use of fopen, fprintf and fclose commands related to file input-output PROGRAM: clc; clear all; close all; A(1)=1; for i=1:4 A(i+1)=A(i)+2; end; fid=fopen('odd.txt','w'); fprintf(fid,'First five odd numbers\n'); fprintf(fid,'*********************\n'); fprintf(fid,'%3i\n',A); fclose(fid); OUTPUT: First five odd numbers ****************** 1 3 5 7 9 RESULT: Thus the various input output functions are studied and program’s were execute. EXPERIMENT NO: 7 DATE:1/04/2015 TITLE: STUDY OF SCILAB GRAPHICS AIM: To study useful commands and functions that can be applied to SCILAB graphics using SCILAB. SOFTWARE REQUIRED: SCILAB QUESTION 1: Plot the given curve by equation y = x^2 where x varies 0 to 10. PROGRAM: clc; clear all; close all; x=0: 1: 10; y=x.^2; plot(x,y) OUTPUT: QUESTION 2: plot a graph for the following variables a = [1 13 6 9 23 12] b = [1-2i,3+4i, 5+6i, 3+8i, 4+9i, 23+12i] PROGRAM: clc; clear all; close all; a=[1 13 6 9 23 12 ] plot(a) b= [1-2i,3+4i,5+6i,3+8i,4+9i,23+12i] plot(b) OUTPUT: QUESTION 3: Plot the curve given by equation y = sin(x), as x varies from 0 to 2π .Also label the x-axis and y-axis and provide a suitable title to the plot. PROGRAM: clc; clear all; close all; x=0:pi/100: 2*pi; y=sin(x); plot(x,y); xlabel('x-axis'); ylabel('y-axis'); title('plot of sine wave'); OUTPUT: QUESTION 4:Plot the curve given by the equation a = 10 e^-t for t = 0 to 5 show the f=grid lines on the plot. PROGRAM: clc; clear all; close all; t=0:0.1:5; a=10*exp(-t); plot(t,a); xlabel('time(t) in sec'); ylabel('output'); title('plot of a=10*exp(-t)'); grid on; OUTPUT: QUESTION 5:Plot the function b=4a^2 for 0< a <20 and illustrate the box command. PROGRAM: clc; clear all; close all; a=0:0.05:20; b=4*a.^2; plot(a,b); box off; xlabel('x-axis'); ylabel('y-axis'); title('plot of function b=4*a.^2 '); OUTPUT: QUESTION 6: Illustrate the use of gtext command on the plot of the equation y = 3x + 5 for x = 0 to 10. PROGRAM: clc; clear all; close all; x=0:0.5:10; y=3*x+5; plot(x,y); gtext('it is a straightline'); grid on xlabel('x-axis----->time (t)'); ylabel('y-axis----->output (y)'); title('plot of y=3*x+5 '); OUTPUT: QUESTION 7: Illustrate the use of axis command with specified limits for plot of function y = 3𝑥 2 + 2𝑥 + 5 for x = -5 to 10. PROGRAM: clc; clear all; close all; x=-5:0.1:10; y=3*x.^2+2*x+5; plot(x,y); axis([-5 5 0 20]); xlabel('x-axis'); ylabel('y-axis'); title('plot of function y=3.x62+2.x+5 '); grid on OUTPUT: QUESTION 8: Illustrate the use of plot command for generating multiple plots PROGRAM: clc; clear all; close all; x1=0:0.1:20; y1=(0.1*x1).*sin(x1); x2=0:0.1:20; y2=sin(x2); x3=0:0.1:20; y3=cos(x3); plot(x1,y1,x2,y2,x3,y3); gtext('curve y1');gtext('curve y2');gtext('curve y3') title('multiple plot using plot command'); xlabel('x-axis'); ylabel('y-axis'); grid on ; OUTPUT: QUESTION 9: Illustrate the use of hold command for generating multiple plots PROGRAM: clc; clear all; close all; x=0:0.5:10; y1=5+4*x; plot(x,y1); hold on; y2=x.^2; plot(x,y2); hold off; gtext(' y1=5+4*x'); gtext('y2=x.^2'); title('multiple plot using hold command'); xlabel('x-axis'); ylabel('y-axis'); OUTPUT: QUESTION 10: Illustrate the use of line command to generate multiple plots. PROGRAM: clc; clear all; close all; x=1:0.1:100; y1=sqrt(x.^2+1); y2=5*x+20; y3=10*x+20; plot(x,y1); gtext('y1=sqrt(x.^2+1)'); line(x,y2); gtext('y2=5*x+20'); line(x,y3); gtext('y3=10*x+20'); title('multiple polts using line command'); grid on; OUTPUT: QUESTION 11: Illustrate the different style options as used in plots. PROGRAM: clc; clear all; close all; t=0:0.1:10; y1=3*t.^2+5*t+6; y2=t.^3+4; plot(t,y1,'r',t,y2,'mo'); xlabel('x-axis'); ylabel('y-axis'); title('plot illustrating use of style option'); grid on; OUTPUT: QUESTION 12: The table below gives of induced voltage E1 V/s field current If,for a dc generator operating at N = 1500 rpm, plots the open circuit characteristics for this generator at 1500 rpm, 1200 rpm and 1000 rpm on the same sheet (Note E α N).Use the proper hold and legend commands. If 0 0.4 0.1 1.45 2.0 3.0 4.0 5.0 6.0 E1 5 30 70 110 PROGRAM: clc; clear all; close all; If=[0.0 0.4 1.0 1.45 2.0 3.0 4.0 5.0 6.0]; E1=[5 30 70 110 150 215 240 250 260]; plot(If,E1,'-'); hold on; E2=(1200/1500)*E1; plot(If,E2,':'); E3=(1000/1500)*E1; plot(If,E3,'-.'); legend('1500rpm','1200rpm','1000rpm'); hold off; title('use of legend command'); xlabel('x-axis'); ylabel('y-axis'); OUTPUT: 150 245 240 250 260 QUESTION 13: Divide the figure window onto four sub-windows and plot the following functions: 1. 2. 3. 4. Plot v v/s I, where v = 4*I and I = 1, 2, 3, 4, on the upper left sub-window. Plot y v/s x, where y = 𝑥 2 and x = 1, 2, 3, 4, on the upper right sub-window. For t = 0:2 * pi in step t = pi/60, plot sin(t) v/s t on the lower left sub-window. For t = 0: pi/30:2 * pi, plot cos(t) v/s t on the lower right sub-window. PROGRAM: clc; clear all; close all; I=1:4; v=4*I; subplot(2,2,1); plot(I,v); title('voltage v/s current'); xlabel('I-amps'); ylabel('v-volt'); x=[1 2 3 4]; y=[1 4 9 16]; subplot(2,2,2); plot(x,y); title('parabolic plot'); xlabel('x--->'); ylabel('y--->'); t=0:pi/60:2*pi; subplot(2,2,3); plot(t,sin(t)); xlabel('t--->'); ylabel('sin(t)'); title('plot of sine function'); subplot(2,2,4); plot(t,cos(t)); xlabel('t--->'); ylabel('cos(t)'); title('plot of cos function'); OUTPUT: QUESTION 14: Plot function x = 𝑒 −𝑎 , y = 𝑎2 where 0<=a<=10, using semilogx function. PROGRAM: clc; clear all; close all; time=0:0.2:8; w=190*(1-exp(-0.15*time)); torque=8*exp(-0.15*time); power=w.*torque; semilogy(time,power) grid on xlabel('Time ''t''[linear scale]'); ylabel('power=w.*torque[logarithmic scale]'); title('Illustrate the use of semilogy command') OUTPUT: QUESTION 15: plot power v/s time for 0<t<8 sec, with power on the log scale and time in the linear scale of a motor whose performance equations are given as follows: Rotational speed, w = 190(1 - 𝑒 −0.15𝑡 ) Torque, T = 8𝑒 −0.15𝑡 Power = w x T PROGRAM: clc; clear all; close all; time=0:0.2:8; w=190*(1-exp(-0.15*time)); torque=8*exp(-0.15*time); power=w.*torque; semilogy(time,power) grid on xlabel('Time ''t''[linear scale]'); ylabel('power=w.*torque[logarithmic scale]'); title('Illustrate the use of semilogy command') OUTPUT: QUESTION 16: plot magnitude v/s frequency on log-log scale for the transfer function 1 G(s) = 1+0.02𝑠 Where s = jw = j2πf and f is the frequency. PROGRAM: clc; clear all; close all;% %program used to illustrate the use of loglog command %Plot loglog graph beween frequency and magnitude of given function freq=1:2:1000; Gs=1./(1+j*2*pi*freq*0.02); mag=abs(Gs); loglog(freq,mag); grid on; xlabel('Frequency''f''[Logarthemic scale]'); ylabel('Magnitude [Logarthemic scale]'); title('Illustrate the use loglog command'); OUTPUT: QUESTION 17: Plot the following fuction on a polar plot 𝝅 f(𝜃) = sin 4θ for- - 𝟐 ≤ θ ≤ 𝝅 𝟐 where θ is radius PROGRAM: clc; clear all; close all; %Program to illustrate the use of polar command %Plot function f = sin(4*theta) as per the given data theta = -pi/2:pi/40:pi/2; f = sin(4.*theta); polar(theta,f,'r-'); title('Plot of funcion f = sin(4*theta) using polar function'); OUTPUT: QUESTION 18: The area function is similar to plot function except the area under plot is filled with colour. The syntax is given as area(x, y). PROGRAM: clc; clear all; close all; %Program to plot y = cos(x) as x varies from 0 to 4pi using area function x=0:0.02:4*pi; y=cos(x); area(x,y); xlabel('x-axis'); ylabel('cos x'); title ('graph to plot y = cos (x) using area function'); OUTPUT: QUESTION 19: Plot a bar graph for the data given as x = [0 1 2 3 4 5 6] and y = [10 15 25 20 30 27 19] PROGRAM: clc; clear all; close all; %program to show bar function x=[ 0 1 2 3 4 5 6]; y=[10 15 25 20 30 27 19 ]; bar(x,y, 'c'); xlabel('x-axis'); ylabel('y-axis'); title('graph to show bar function'); OUTPUT: QUESTION 20: Plot a bar graph to show the comparison of average temperature in City A, B, and C for the months from September to February. The data is given as City A City B City C September 31 28 24 October 29 26 22 November 28 25 20 December 27 24 16 January 26 22 17 February 29 25 20 PROGRAM: clc; clear all; close all; %Program to show average Temparature of city A, B and C for %months from sept to feb using bar graph temp=[31,28,24; 29 26 22;28 25 20; 27 24 16; 26 22 17; 29 25 20]; bar(temp,'group'); ylabel('Temparature in Celcius'); xlabel('Months from Sept to Feb'); legend('City A','City B','City C'); title ('temperature of City A, City B and City C for months from September to February'); OUTPUT: QUESTION 21: Illustrate the use or barh function of x = [0 1 2 3 4 5 6] and y = [10 15 25 20 30 27 19] PROGRAM: clc; clear all; close all; %program to show 'barh' function x=[0 1 2 3 4 5 6]; y=[10 15 25 20 30 27 19]; barh(x,y, 'g'); xlabel(x-axis); ylabel(y-axis); title('Graph to show barh function'); OUTPUT: QUESTION 22: Illustrate the use of hist function PROGRAM: clc; clear all; close all; %program to illustrate the use of hist function x=randn(100,1)*pi; hist(x); title('Histogram to show 100-random values in 10-bins'); OUTPUT: QUESTION 23: Illustrate the use of hist function with 15 bins PROGRAM: clc; clear all; close all; %program to illustrate the use of hist function with 15 bins x=randn(200,1); hist(x,15); title('Histogram to show 200 random values in 15-bins'); OUTPUT: QUESTION 24: Illustrate the use of hist function with no. of bins specified in a vector p. PROGRAM: clc; clearall; closeall; %program to illustrate the use of hist function with no. of bins specified %by a vector x=randn(300,1); p=-2:0.1:2; hist(x,p); title('Histogram to show 300 random values in no. of bins specified by a vector'); OUTPUT: QUESTION 25 :Illustrate the use of rose function PROGRAM: clc; clearall; closeall; %Program to illustrate the use of rose function x=randn(100,1)*pi; %Generate 100 random data points %Draw the Histogram with no. of bins in vector p rose(x) title('Polar histogram to show 100 random values using rose function'); OUTPUT: QUESTION 26: Illustrate the use of rose function PROGRAM: %Program to illustrate the use of rose function x=randn(500,1)*pi; %Generate 500 random data points %Specifies the number of bins in a vector v v=-pi:0.5:pi; %Draw the histogram with no. of bins in vector rose (x,v); title('Polar Histogram using rose function with no. of bins specified by a vector'); OUTPUT: QUESTION 27: Illustrate the use of pie function to show the concentration of different industries in the region as per the following data NAME OF THE INDUSTRY NO. OF INDUSTRIAL UNITS Cement 4 Textile 8 Software 20 Chemical 2 Telecom 7 Banking 10 PROGRAM: clc; clearall; closeall; %program to draw a pie chart showing concentration of different Industries %in a region industry=[4 8 20 2 7 10]; pie(industry); title('Pie chart showing concentration of different industries'); OUTPUT: QUESTION 28: Repeat question 27 to show sliced pie chart PROGRAM: clc; clearall; closeall; %program to draw a sliced pie chart showing concentrtion of different %industries in a region industry =[4 8 20 2 7 10]; show =[0 0 0 1 0 1]; pie(industry, show) title('Sliced Pie chart showing the concentration of Different industries'); legend('Cement','Textile','Software','Chemical','Telecom','Banking',3); OUTPUT: QUESTION 29: Illustrate the use of pie chart NAME OF THE INDUSTRY NO. OF INDUSTRIAL UNITS Cement 4 Textile 8 Software 20 Chemical 2 Telecom 7 Banking 10 PROGRAM: clc; clear all; close all; %program to draw a pie chart showing the concentration of different %industries in a region industry =[4 8 20 2 7 10]; show =[0 1 0 0 1 0]; label= ({'cement','Textiles','Software','Chemical','Telecom','Banking'}); pie(industry,show,label); title('Labelled and Sliced Pie chart showing the concentration of Different industries') OUTPUT: QUESTION 30:Draw the stairs plot to show the function y=x.*x,where -2<=x<=2 PROGRAM: clc; clear all; close all; %Program to show stairs plot to show the function y = x.*x x=-2:0.1:2; y=x.*x; stairs(x,y,'r'); grid on; xlabel(' x-axis'); ylabel('y = x.*x'); title('Stairs plot to show the function y = x.*x'); OUTPUT: QUESTION 31: Draw the stairs plot for the following data: X = [0 2 3 4 5 7] Y = [5 -1 8 4 7 3] PROGRAM: clc; clear all; close all; %program to Illustrate the stairs function x = [0 2 3 4 5 7]; y = [5 -1 8 4 7 3]; stairs(x,y,'*-.'); box off; title('Graph to Illustrate stairs function'); xlabel('x-axis'); ylabel('y-axis'); OUTPUT: QUESTION 32: Draw the stem plot for the following data: X=[0 1 2 3 4 5 6] Y=[3 -1 6 -4 5 2 3] PROGRAM: clc; clear all; close all; %program to Illustrate stem function x = [0 1 2 3 4 5 6 ]; y = [3 -1 -6 4 5 2 3]; stem(x,y); title('Graph to Illustrate the stem function'); xlabel('x-label'); ylabel('y-axis'); OUTPUT: QUESTION 33: Draw the compass plot for the following data: Z=[1+1i 4-8i 20+7i 6+8i 9+2i 12-4i] PROGRAM: clc; clear all; close all; %program to Illustrate the compass function z= [1+1i 4-8i 20+7i 6+8i 9+2i 12-4i]; compass(z); title('Graph to Illustrate the compass function'); OUTPUT: QUESTION 34: Given is x=t2 and y=4t for -4<t<4.Obtain a 3-D plot showing the matrix in (x,y) space as a factors for time PROGRAM: clc; clearall; closeall; %program to illustrate the plot3 funtion t=-4:0.1:4; x=t.^2; y=4*t; plot3(x,y,t); gridon; xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis'); title('illustrate of plot3 function'); OUTPUT: QUESTION 35: Draw 3-D bar graph for following data X=[0 1 2 3 4 5 6] Y=[5 17 25 21 31 27 19] PROGRAM: clc; clearall; closeall; %program to plot 3-D graph using bar3 functtion x=[ 0 1 2 3 4 5 6]; y=[5 17 25 21 31 27 19 ]; bar3(x,y,'g'); xlabel('x-axis'); ylabel('y-axis'); title('Graph to show bar3 function'); OUTPUT: QUESTION 36:Draw a 3-D horizontal bar to show the growth of a state as per the following date: Year=[1992 1993 1994 1995 1996 1997 1998] Growth (in % age) = [12 15 10 8 6.5 9 11] PROGRAM: clc; clearall; closeall; %program to illustrate use of bar3h function function year=[1992 1993 1994 1995 1996 1997 1998]; growth=[12 15 10 8 6.5 9 11]; bar3h(year,growth,'c'); title('Yearly growth using bar3h function'); zlabel('Year'); ylabel('Precentage growth'); OUTPUT: QUESTION 37:Illustrate the use of pie3 function to show different profession people in a group as per the following data: Profession No. Of Persons Manager 12 Engineer 15 Professor 13 Doctor 11 Architect 6 Designer 10 PROGRAM: clc; clearall; closeall; %Program to Illustrate use of pie3 function person = [{'Manager','Engineer','Professor','Doctor','Architect','Designer'}]; strength=[12 15 13 11 6 10]; explode= [0 0 1 0 0 1]; pie3(strength,explode,person); title('Person in a group using pie3 function'); OUTPUT: QUESTION 38: Write a program to illustrate the use of stem3 function to plot the following function: y = xcos(x); z = exp(x/5)cos(x) + 1 for 0 ≤ x ≤ 6π. PROGRAM: clc; clearall; closeall; %Program to Illustrate the stem3 command x=linspace(0,6*pi,200); y=x.*cos(x)+1; z=exp(x/5).*cos(x)+1; stem3(x,y,z); title('Graph to Illustrate stem3 function'); xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis'); OUTPUT: QUESTION 39: Create meshgrid for the data -1 ≤ x ≤ 1 and -2 ≤ y ≤ 2. PROGRAM: clc; clearall; closeall; [x,y]= meshgrid(-1:0.5:1, -2:1:2) OUTPUT: QUESTION 40: Create a mesh plot of the function z = 2/(𝑥 2 + 𝑦 2 +1) over the interval -5 ≤ x ≤ 5 and -5 ≤ y ≤ 5. PROGRAM: clc; clearall; closeall; %Program to Illustrate the mesh function [x,y]=meshgrid(-5:0.1:5); ;z=2./(x.^2+y.^2+1); mesh(x,y,z); gridon; title('Program to illustrate the mesh function'); xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis'); OUTPUT: QUESTION 41: Create a surface plot of the function f(x,y) = 8-𝑥 2 − 9𝑦 2 over the interval -2 ≤ x ≤ 2 and -3 ≤ y ≤ 3. PROGRAM: clc; clearall; closeall; %Program to illustrate the surf function [x,y]= meshgrid (-2:0.1:2, -3:0.5:3); z = 8-x.^2-9*y.^2; surf(x,y,z); gridon; title('Program to illustrate the surf function'); xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis'); OUTPUT: QUESTION 42:Create a contour 3-D plot of the function z = sqrt(y.^2-x.^2) over the interval -3 ≤ x ≤ 3 and -3 ≤ y ≤ 3. PROGRAM: clc; clearall; closeall; %Program to illustrate the contour3 function [x,y]=meshgrid(-3:0.5:3, -3:0.5:3); z=sqrt(y.^2-x.^2); contour3(x,y,z); gridon; title('Program to illustrate the contur3 function'); xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axos'); OUTPUT: RESULT: Thus the programs related to SCILAB Graphics are studied and executed.