Name: Sruthi G Regno: 24137110580 45 EX NO: 1 Implementation Of Basic Matrix Operation s AIM: To implement and perform basic matrix operations such as addition, subtraction, multiplication, and transpose using Scilab. CODE: A = [1, 2, 3; 4, 5, 6; 7, 8, 9]; disp("Matrix A:"); disp(A); B = [9, 8, 7; 6, 5, 4; 3, 2, 1]; disp("Matrix B:"); disp(B); disp("Sum of matrices A and B:"); disp(A + B); disp("Difference of matrices A and B (A - B):"); disp(A - B); disp("Multiplication of matrices A and B:"); disp(A * B); disp("Transpose of matrix A:"); disp(A'); disp("Transpose of matrix B:"); disp(B'); disp("Determinant of matrix A:"); disp(det(A)); disp("Determinant of matrix B:"); disp(det(B)); OUTPUT: Name: Sruthi G Regno: 24137110580 45 RESULT: Thus, the basic matrix operations were successfully implemented and verified using Scilab. Name: Sruthi G Regno: 24137110580 45 Ex No: 2 Matrix manipulation AIM: To perform matrix manipulation operations using Scilab. CODE: M = [1, 2, 3; 4, 5, 6; 7, 8, 9]; disp("Matrix M:"); disp(M); disp("Diagonal elements of M:"); disp(diag(M)); disp("Identity matrix: "); disp(eye(4,4)); disp("Ones matrix:"); disp(ones(3,3)); disp("Zeros matrix:"); disp(zeros(4,2)); disp("Random matrix:"); disp(rand(2,3)); disp( "Inverse of matrix M:"); disp(inv(M)); disp("Determinant of matrix M:"); disp(det(M)); OUTPUT: Name: Sruthi G Regno: 24137110580 45 RESULT: Thus, various matrix manipulation operations were successfully implemented using Scilab. Name: Sruthi.G Regno: 24137110580 45 Ex No: 3 Triangular Membership Function AIM: To implement and plot a triangular membership function using fuzzy logic concepts in Scilab. CODE: x = linspace(0, 2, 100)'; y1 = trimf(x, [0 0.2 0.4]); y2 = trimf(x, [0.2 0.5 0.9]); y3 = trimf(x, [0.5 0.6 0.9]); scf( ); clf(); plot2d(x, [y1 y2 y3], leg="y1@y2@y3"); xtitle("Triangular Membership Function", "x", "mu(x)"); OUTPUT: RESULT: Thus, the triangular membership functions were successfully implemented and plotted using Scilab Name: Sruthi.G Regno: 24137110580 45 Ex No: 4 Trapezoidal Membership Function AIM: To implement and plot a trapezoidal membership function using fuzzy logic concepts in Scilab. CODE: x = linspace(0, 1, 100)'; y1 = trapmf(x, [0 0.2 0.4 0.6]); y2 = trapmf(x, [0.2 0.5 0.6 0.9]); scf(); clf(); plot2d(x, [y1 y2], leg="y1@y2"); xtitle("Trapezoidal Membership Function", "x", "y"); OUTPUT: RESULT: Thus, the trapezoidal membership functions were successfully implemented and plotted using Scilab. Name: Sruthi.G Regno: 24137110580 45 Ex No: 5 Z - Shaped Membership Function AIM: To implement and plot a Z - shaped membership function using fuzzy logic concepts in Scilab. CODE: x = linspace(0, 1, 100)'; y1 = zmf(x, [0 0.2]); y2 = zmf(x, [0.2 0.4]); y3 = zmf(x, [0.4 0.6]); y4 = zmf(x, [0.6 0.8]); scf(); clf(); plot2d(x, [y1 y2 y3 y4], leg="y1@y2@y3@y4"); xtitle("Z - Shaped Membership Function", "x", "y"); OUTPUT: RESULT: Thus, the Z - shaped membership functions were successfully implemented and plotted using Scilab. Name: Sruthi.G Regno: 24137110580 45 Ex No: 6 Gaussian Membership Function AIM: To implement and plot a Gaussian membership function using fuzzy logic concepts in Scilab. CODE: x = linspace(0, 1, 100)'; y1 = gaussmf(x, [2 5]); y2 = gaussmf(x, [3 7]); y3 = gaussmf(x, [4 8]); scf(); clf(); plot2d( x, [y1 y2 y3], leg="y1@y2@y3"); xtitle("Gaussian Membership Function", "x", "y"); OUTPUT: RESULT: Thus, the Gaussian membership functions were successfully implemented and visualized using Scilab. Name: Sruthi.G Regno: 24137110580 45 Ex No: 7 Extended Gaussian Membership Function AIM: To implement and plot an extended Gaussian membership function using fuzzy logic concepts in Scilab. CODE: x = linspace(0, 1, 100)'; y1 = gauss2mf(x, [0.2 0.4 0.1 0.8]); y2 = gauss2mf(x, [0.3 0.5 0.2 0.7]); y3 = gauss2mf(x, [0.3 0.5 0.6 0.9]); scf(); clf(); plot2d(x, [y1 y2 y3], leg="y1@y2@y3"); xtitle("Extended Gaussian Membership Function", "x", "y"); OUTPUT: RESULT: Thus, the extended Gaussian membership functions were successfully implemented and plotted using Scilab. Name: Sruthi.G Regno: 24137110580 45 Ex No: 8 Generalized Bell Membership Function AIM: To implement and plot a generalized bell - shaped membership function using fuzzy logic concepts in Scilab. CODE: x = linspace(0, 1, 100)'; y1 = gbellmf(x, [0.5 10 1]); y2 = gbellmf(x, [0.5 10 0.5]); y3 = gbellmf(x, [0.5 10 1]); scf(); clf(); plot2d(x, [y1 y2 y3], leg="y1@y2@y3"); xtitle("Generalized Bell Membership Function", "x", "y"); OUTPUT: RESULT: Thus, the generalized bell - shaped membership functions were successfully implemented and plotted using Scilab. Name: Sruthi.G Regno: 24137110580 45 Ex No: 9 Sigmoidal Membership Function AIM: To implement and plot a sigmoidal membership function using fuzzy logic concepts in Scilab. CODE: x = linspace(0, 1, 100)'; y1 = sigmf(x, [12 0.3]); y2 = sigmf(x, [12 0.5]); y3 = sigmf(x, [ - 12 0.5]); y4 = sigmf(x, [ - 12 0.7]); scf(); clf(); plot2d(x, [y1 y2 y3 y4], leg="y1@y2@y3@y4"); xtitle("Sigmoidal Membership Function", "x", "y"); OUTPUT: RESULT: Thus, the sigmoidal membership functions were successfully implemented and visualized using Scilab Name: Sruthi.G Regno: 24137110580 45 Regno 3 2 2 24137110580 45 2413 2413711058024 Ex No: 10 Defuzzification Methods AIM: To study and implement different defuzzification methods using Scilab. CODE: x = linspace(0, 1, 100)'; mf1 = max( 0.6 * trimf(x, [0 0.2 0.4]), 0.4 * trimf(x, [0.3 0.6 0.9]) ); scf(); clf(); plot2d(x, mf1); xtitle("Defuzzification Methods", "x", "μ(x)"); Yc = defuzzm(x, mf1, "centroide"); Yb = defuzzm(x, mf1, "bisector"); Ylom = defuzzm(x, mf1, "lom"); Ysom = defuzzm(x, mf1, "som"); Ymom = defuzzm(x, mf1, "mom"); disp( "Centroid value:", Yc); disp("Bisector value:", Yb); disp("LOM value:", Ylom); disp("SOM value:",Ysom); disp("MOM value:", Ymom); OUTPUT: Name: Sruthi.G Regno: 24137110580 45 Regno 3 2 2 24137110580 45 2413 2413711058024 RESULT: Thus, various defuzzification methods were successfully implemented and their output values were obtained. Name: Sruthi.G Regno: 24137110580 45 Ex No: 11 Graphical User Interface AIM: To design and implement a graphical user interface (GUI) for a fuzzy logic system using Scilab. CODE: f = createWindow(); f.axes_size = [230 180]; f.figure_name = "My Interface"; uicontrol(f, "style", "pushbutton", "string", "Call My Script", "position", [50 75 130 40],"callback", "regr"); OUTPUT: RESULT: Thus, a simple graphical user interface with a push button was successfully created using Scilab. Name: Sruthi.G Regno: 24137110580 45 Ex No: 12 Control Structures AIM: To implement and analyze control structures using Scilab. (a) IF – ELSE CODE: avg_mark = input("Enter the average mark: "); if avg_mark >= 75 then disp("Passed with Distinction"); elseif avg_mark >= 60 then disp("Passed with First Class"); elseif avg_mark >= 45 then disp("Passed with Second Class"); elseif avg_mark >= 0 then disp("Failed"); end OUTPUT: Name: Sruthi.G Regno: 24137110580 45 (b) While Loop CODE: x = 10; while x > 0 x = x - 3; disp(x); if x < 3 then break; end end OUTPUT: (c) For Loop CODE: u(1) = 4; for n = 1:10 u(n+1) = u(n) + 2*n + 3; disp([n u(n)]); end OUTPUT: RESULT: Thus, control structures were successfully implemented and executed in Scilab Name: Sruthi.G Regno: 24137110580 45 Ex No: 13 Implementation of Fuzzy inference system – Service Incentive in a Restaurant AIM: To implement a Fuzzy Inference System for calculating the tip amount in a restaurant using SciLab. EXECUTION: Information Description Name: Sruthi.G Regno: 24137110580 45 Input Variables Output Variable Name: Sruthi.G Regno: 24137110580 45 Rules Plot Current Variables Name: Sruthi.G Regno: 24137110580 45 OUTPUT: Case 1 – Low tip Case 2 – Medium tip