SCILAB Edited
SCILAB Edited
SCILAB Edited
SCILAB CONSOLE
The first way is to use Scilab interactively, by typing commands in the console, analyzing
the results and continuing this process until the final result is computed. This document is
designed so that the Scilab examples which are printed here can be copied into the console. The
goal is that the reader can experiment by himself Scilab behavior. This is indeed a good way of
understanding the behavior of the program and, most of the time, it allows a quick and smooth
way of performing the desired computation.
In the following example, the function disp is used in the interactive mode to print out the
string Hello World!.
The completion in the console.
-->s="Hello World!" s =
Hello World! -->disp(s)
Hello World!
In the previous session, we did not type the characters -->which is the prompt, and which
is managed by Scilab. We only type the statement s="Hello World!" with our keyboard and then
hit the <Enter> key. Scilab answer is s = and Hello World!. Then we type disp(s) and Scilab
answer is Hello World!.
When we edit a command, we can use the keyboard, as with a regular editor. We can use the
left and right arrows in order to move the cursor on the line and use the <Backspace>and
<Suppr>keys in order to fix errors in the text.
In order to get access to previously executed commands, use the up arrow key. This allows
to browse the previous commands by using the up and down arrow keys.
The <Tab>key provides a very convenient completion feature. In the following session, we
type the statement disp in the console.
-->disp
Then we can type on the <Tab>key, which makes a list appear in the console, as presented
in figure 4. Scilab displays a listbox, where items correspond to all functions which begin with
the letters disp. We can then use the up and down arrow keys to select the function we want.
The auto-completion works with functions, variables, files and graphic handles and makes
the development of scripts easier and faster.
The editor
Scilab version 5.2 provides a new editor which allows to edit scripts easily. Figure 5 presents
the editor during the editing of the previous Hello World! example.
The editor.
The editor can be accessed from the menu of the console, under the Applications > Editor
menu, or from the console, as presented in the following session.
-->editor()
This editor allows to manage several files at the same time, as presented in figure 5, where
we edit five files at the same time.
There are many features which are worth to mention in this editor. The most commonly
used features are under the Execute menu.
Load into Scilaballows to execute the statements in the current file, as if we did a copy
and paste. This implies that the statements which do not end with the semicolon ;
character will produce an output in the console.
Evaluate Selection allows to execute the statements which are currently selected.
Execute File IntoScilaballows to execute the file, as if we used the exec function. The
results which are produced in the console are only those which are associated with
printing functions, such as disp for example.
We can also select a few lines in the script, right click (or Cmd+Click under Mac), and get the
context menu which is presented in figure 6.
The Edit menu provides a very interesting feature, commonly known as a pretty printer in
most languages. This is the Edit > Correct Indentation feature, which
Context menu in the editor.
automatically indents the current selection. This feature is extremelly convenient, as it allows to
format algorithms, so that the if, for and other structured blocks are easy to analyze.
The editor provides a fast access to the inline help. Indeed, assume that we have selected the
disp statement, as presented in figure 7. When we right-click in the editor, we get the context
menu, where the Help about disp entry allows to open the help page associated with the disp
function.
STUDY EXPERIMENT - 2
ans answer
Control flow
Variables
Predefined variables
SCIHOME contains the path to preferences, history files of your Scilab session.
%e Euler number.
%i imaginary unit
%inf infinity
%nan not-a-number
perl Call Perl script using appropriate operating system executable. This function is
obsolete.
scilab Main script to start Scilab and miscellaneous tools (GNU/Linux, Unix and
Mac OS X)
Elementary Functions
Bitwise operations
bitor bitwise OR
Complex
Discrete mathematics
Elementary matrices
log1p computes with accuracy the natural logarithm of its argument added by one
Floating point
ceil round up
Radix conversions
Matrix manipulation
max maximum
min minimum
norm matrix norm
Set operations
members count (and locate) in an array each element or row or column of another
array
Trigonometry
tan tangent
Linear Algebra
pbig eigen-projection
show_margins display gain and phase margin and associated crossover frequencies
Polynomials
denom denominator
residu residue
Date:
ALGORITHM:
Step 1: Start the Scilab Software
Step 2: Get the input values for matrix
Step 3: Perform matrix operation using corresponding values
Step 4: Store the output values using some variables
Step 5: Stop
PROGRAM:
Matrices Commands:
Let matrix A be defined as follows:
A=[1 2; 0 4]
i.e., A=1 2
0 4
Commands:
1. det(A)
It returns the determination of a given square matrix A
OUTPUT:Ans=4
2. rank(A)
It returns the rank of a given rectangular matrix A
OUTPUT:Ans=2
3. trace(A)
It returns the sum of the diagonal elements of a rectangular matrix A
OUTPUT:Ans=5
4. inv(A)
It returns the inverse of a non-singular matrix A(i.e., A^-1)
OUTPUT:
Ans= 1.0000 -0.5000
0 0.2500
5. norm(A)
It returns the Euclidean norm of the given rectangular matrix A
OUTPUT:
Ans=4.4954
6. A(A transpose)
It returns the transpose of the specified rectangular matrix A
OUTPUT:
Ans=
1 0
2 4
8. find(A)
This function returns the row and column indices of the non-zero entries in the matrix A
OUTPUT:
Ans=
1
3
4
Matrix Manipulation Commands:
1.Reshaping of a matrix as a vector:
1 10 20
Let matrix A = 2 5 6 Reshape the matrix to a column vector.
7 8 9
Solution:
This command converts the matrix A to a column vector, B
A=[1 10 20; 2 5 6; 7 8 9]
B=A(:)
OUTPUT:
Ans=
B= 1
2
7
10
5
8
20
6
9
A(2,3)=15
OUTPUT:
Ans=
A=6 7 0
8 9 15
Solution:
I) A=[6 7; 8 9]
X=[1 ; 2]
B=[A X]
II) A=[6 7;8 9]
Y=[3 4]
C=[A ;Y]
OUTPUT:
Ans=
B=6 7 1
8 9 2
C=6 7
8 9
3 4
5. Concatenation of matrices:
This command is used to join or combine small matrices together to make larger matrices or
bigger matrices.
Let matrix A be given by A= 1 2 . Compute matrix B where B= A1 A2 where the sub-
3 4 A3 A4
matrices, A1=A, A2=A+1, A3=A+24, A4=A+10
Solution:
A=[1 2; 3 4]
B=[ A A+1 ; A+24 A+10]
OUTPUT:
Ans=
B=
1 2 2 3
3 4 4 5
25 26 11 12
27 28 13 14
RESULT: Thus the matrix and manipulation commands are executed and output is verified
successfully.
Ex No: 2 POLYNOMIAL COMMANDS
Date:
ALGORITHM:
Step 1: Start the Scilab Software
Step 2: Get the input values for polynomial
Step 3: Perform operation using corresponding values
Step 4: Store the output values using some variables
Step 5: Stop
PROGRAM:
Commands on Polynomials:
1. ROOTS OF POLYNOMIALS
The roots of polynomial can be found by using the following command.
Find the roots of polynomial s^2+3s+2=0
Solution:
p=[1 3 2];
val=roots(p)
OUTPUT:
val =
-2
-1
3. POLYNOMIAL MULTIPLICATION:
The product of two polynomials is obtained by the convolution operation of their coefficients
using the MATLAB function conv.
Evaluate the product of polynomials (s+2) and (s^2+4s+8)
Solution:
a=[1 2];
b=[1 4 8];
c=conv(a,b)
OUTPUT:
c=
1 6 16 16
The resultant polynomial is s^3+6s^2+6s+16
Solution:
a=[0 1; 2 3];
p=poly(a,x)
OUTPUT:
p =x2 -3x -2
The resultant polynomial is s^2-3s-2
RESULT:Thus the polynomial commands are executed and output is verified successfully.
Ex No: 3 PROGRAM ON RELATIONAL OPERATIONS
Date:
AIM:
To execute a Scilab program by using Relational operators.
ALGORITHM:
Step 1: Start the program.
Step 2: Assign the values for X matrix in program.
Step 3: Compare X with a matrix using relational operator
Step 4: Display True and false values according to the elements in matrix.
Step 5: End the program.
PROGRAM:
X=5*ones(3,3);
X >=[1 2 3;4 5 6;7 8 9];
OUTPUT:
111
110
000
RESULT:Thus the program using relational operator is executed and output is verified
successfully.
Ex No: 4 PROGRAM ON BITWISE OPERATIONS
Date:
AIM:
To execute a scilab program to perform bitwise operations using a function and to create a
xor gate using and and or gates.
ALGORITHM:
Step1: Start the program.
Step 2: Create a function named as Xor.
Step 3: Get the values of x and y from the user in runtime.
Step 4:Execute the following line of codes:
a=bitand(x,y);
b=bitcmp(a,1);
c=bitor(x,y);
d=bitand(b,c);
Step 5: Display the value of d using display function.
Step 6: End the function using end function.
Step 7: End the program.
PROGRAM:
[x,y]=([0 0 1 1],[0 1 0 1])
a=bitand(x,y);
b=bitcmp(a,1);
c=bitor(x,y);
d=bitand(b,c);
disp("after xor gate ")
disp(d);
OUTPUT:
[x,y]=xor([ 0 0 1 1 ], [ 0 1 0 1 ] )
after xor gate
0. 1. 1. 0.
y =
0. 1. 0. 1.
x =
0. 0. 1. 1.
RESULT:Thus the program using bitwise operatorsis executed and output is verified
successfully.
Ex No: 5 PROGRAM ON LOGICAL OPERATIONS
Date:
AIM:
To execute a Scilab program by using Logical operators.
ALGORITHM:
Step 1: Start the program.
Step 2: Assign the values for a and b in program.
Step 3: Execute the following line of codes:
a&&b
a||b
(~(a&&b)
Step 4: Display the statements according to the logical operator using display function.
Step 5: End the program.
PROGRAM:
a=00;b=10;
if a&b
disp(Condition is true);
else
disp(Condition is false);
end
if a|b
disp(Condition is true);
end
if (~(a&b))
disp(Condition is true);
end
OUTPUT:
Condition is false
Condition is true
Condition is true
RESULT:Thus the program using logical operators is executed and verified successfully.
PROGRAM TO FIND LARGEST OF FIVE NUMBERS USING IF CONDITION
Ex.No:6
Date:
AIM:
To write a Scilab program to find the largest of five numbers using if condition.
ALGORITHM:
Step 1: Start
Step 2: Accept three numbers from the user
Step 3: Initialize a variable s with 0 which is taken as the smallest number for the time
being
Step 4: Run a loop of three iterations which will change the value of initialize variable to the
number greater than it each time if found.
Step 5: Display the largest number which is stored in the variable s
Step 6:Stop
PROGRAM:
s=0;
for i=1:5
a=input("input the numbers");
if(a>s)then
s=a;
end;
end;
disp(s);
OUTPUT:
Input the numbers: 5, 6, 2, 9, 1
Output:
9
RESULT:Thus the programto find largest of five numbers is executed and output isverified
successfully.
PROGRAM FOR FIBONACCI SERIES USING FOR LOOP
Ex.No:7
Date:
AIM:
To execute a program to display Fibonacci series by using for loop.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input from the user for limit of series.
Step 3: Initialize the value of a and b as 1.
Step 4: Repeat the following step until limit is reached:
s=a+b;
Step 5: Display the series.
Step 6: End the program
PROGRAM:
n=input("Enter the limit");
a=1;
b=1;
s=0;
disp(a);
disp(b);
fori=2:n
s=a+b;
disp(s);
a=b;
b=s;
s=0;
end;
OUTPUT:
Enter the Number 5
1
1
2
3
5
RESULT:Thus the program for Fibonacci series using for loop is executed and output is
verified successfully.
PROGRAM FOR MULTIPLICATION TABLE USING FOR LOOP
Ex.No:8
Date:
AIM:
To execute a program to display Multiplication Table using for loop.
ALGORITHM:
Step1: Start the program.
Step2: Get the input from the user to generateMultiplication table.
Step3: Get the limit from the user.
Step4: Repeat the following step until limit is reached:
f=f*i
Step5: Print the factorial of the number.
Step6: End the program.
PROGRAM:
n=input("Enter a number");
k=input("Enter Limit");
s=0;
fori=1:k
s=n*i;
disp(s);
i=i+1;
end;
OUTPUT:
Enter a number: 5
Enter Limit: 4
5
10
15
20
RESULT:Thusthe above multiplication program using for loop is executed and output is
verified successfully.
PROGRAM FOR FACTORIAL USING WHILE LOOP
Ex No: 9
Date:
AIM:
To execute a program to display factorial of a number using while loop.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input from the user to find factorial for that number.
Step 3: Initiate value of f as 1.
Step 4: Repeat the following step until limit is reached:
f=f*i
Step 5: Print the factorial of the number.
Step 6: End the program.
PROGRAM:
n=input("input a number");
f=1;
while n>0
f=f*i;
end;
disp(f);
OUTPUT:
Factorial of which number: 5
120.
RESULT:Thus the factorial program using while loop is executed and output is verified
successfully.
PROGRAM FOR PRIME NUMBER USING FOR LOOP
Ex No: 10
Date:
AIM:
To execute a Scilab program to check whether a given number is prime number or not.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input from the user to check whether it is prime number or not.
Step 3: Initialize a variable k with 0
Step 4: Run a loop of three iterations which will change the value of initialize variable to the
number greater than it each time if found.
Step 5: Find modulo value using modulo operator
Step 6: Display statement according to the value of k
Step 7: End the program.
PROGRAM:
a=input("enter no");
k=0;
for i=1:a
if(modulo(a,i)==0)then
k=k+1;
end;
end;
if(k==2)then
disp('Prime number');
else
disp("not a Prime number");
end
OUTPUT:
Enter a number:
7
Prime number
9
Not a prime number
RESULT:
Thus the prime numberprogram using while loop is executed and verified successfully.
PROGRAM FOR PALINDROME OF A NUMBER USING WHILE LOOP
Ex.No:11
Date:
AIM:
To execute a program to check whether a given number is palindrome or not using while
loop.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input from the user to find palindrome or not.
Step 3: Initiate value of f as 0.
Step 4: Repeat the following step until condition satisfied
r=modulo(n,10);
n=n-r;
f=(f*10)+r;
n=n/10;
Step 5: Check whether k==f, if display the given number is palindrome.
Step 6: Else Display it is not a palindrome number.
Step 7: End the program.
PROGRAM:
n=input("enter a number");
k=n;
f=0;
while(n>0)
r=modulo(n,10);
n=n-r;
f=(f*10)+r;
n=n/10;
end;
if(k==f)then
disp("Palindrome");
else
disp("Not a palindrome");
end;
OUTPUT:
Enter a number
121
Palindrome
123
Not a palindrome
RESULT: Thus the Palindrome number program using while loop is executed and verified
successfully.
Date:
AIM:
To execute a program to check whether a given String is palindrome or not using if
condition.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the string input from the user and store it variable a.
Step 3: Reverse the string using strrev function and assign it into b
Step 4: Check a==b, if yes display the entered string is palindrome
Step 5: Else display it is not a string palindrome.
Step 6: End the program.
PROGRAM:
a=input(" enter a string","string");
b=strrev(a);
if(a==b)
disp("String is Palindrome");
else
disp("String is not a Palindrome");
end;
OUTPUT:
Enter a string
Madam
String is Palindrome
Enter a string
Chennai
String is not a palindrome
RESULT:Thus the String Palindrome program using if condition is executed and output is
verified successfully.
PROGRAM FOR SUM OF INTEGERS
Ex.No:13
Date:
AIM:
To find the number of integers that are greater than 50 and less than 100 and are divisible by
11, and to find the sum of these numbers.
ALGORITHM:
Step1: Start
Step2: Assign sum=0, c=0
Step3: for i=50, increasing i by 1 upto 100, repeats steps 5 to 7
Step4: if i is divisible by 11, goto step 6 and 7
Step5: Display i, and assign c=i
Step6: sum=sum+c
Step7: Display sum
Step8: Stop the program
PROGRAM:
sum=0;
c=0;
for i=50:1:100
if modulo(i,11)==0
disp(i);
sum=sum+i;
end;
end;
disp(sum);
OUTPUT:
55+66+77+88+99=385
RESULT: Thus the program for sum of integers which are greater than 50 and less than 100
and divisible by 11 is found and output verified successfully.
PROGRAM TO REVERSE A NUMBER
Ex.No: 14
Date:
AIM:
ALGORITHM:
Step 1: Start
Step 2: Get input from the user in variable n
Step 3: while n>0
Step 4: d=mod(n,10)
Step 5: n=fix(n/10)
Step 6: r=r*10+d
Step 7: End while loop
Step 8: Display r
Step 9: Stop the program
PROGRAM:
r=0;
n=input(Enter the number);
while n>0
d=modulo(n,10);
n=fix(n/10);
r=r*10+d;
end;
disp(r);
OUTPUT:
Enter the number 23
32
Enter the number 456
654
RESULT:Thus the reverse of given number is obtained and output was verified successfully.
PROGRAM USING SELECT STATEMENT ON ARITHMETIC OPERATORS
Ex No 15:
Date:
AIM:
To write a Scilab program to perform arithmetic operations using select statement.
ALGORITHM:
Step 1: Start the program
Step 2: Get a input from user and assign it in a variable
Step 3:Get another input from user and assign it in b variable
Step 4:Get the choice from user and assign it in ch variable
Step 5: Perform the following operations using cases
1.Addition 2. Subtraction 3. Multiplication 4.Division
Step 6:Display the result of arithmetic operations according to the choice
Step 7:End the program
PROGRAM:
a=input('enter a number');
b=input('enter second number');
ch=input('Enter your choice');
select ch
case 1 then
c=a+b;
disp(c);
case 2 then
d=a-b;
disp(d);
case 3 then
e=a*b;
disp(e);
case 4 then
f=a/b;
disp(f);
else
disp('Invalid')
end;
OUTPUT:
Enter a number: 5
Enter second number: 6
Enter your choice 3
30
RESULT:
Thus the program to perform arithmetic operations using select statement is executed
and output is verified successfully.
PROGRAM USING SELECT STATEMENT ON DIFFERENT OPERATIONS
Ex.No.16
Date:
ALGORITHM :
Step 1: Start the program.
Step 2: Enter the number to repeat the program
Step 3: Create while loop
Step 4: Enter the choice.
Step 5: Case1: Use if and modulo to check the number is even or odd. Display the result
Step 6: Case 2: Declare n=a and s=0
Take the remainder after dividing the number by 10 using modulo function and assign it
m
Sum=sum*10+m
Divide by 10
Run it till a>0
Check if n=s
Display the result
Step 7: Case 3:
Declare n=a s=0
Take the remainder dividing the number by 10 using modulo function and assign it m
Divide by 10; a=floor(a/10); s=s+m
display the sum; End the while loop ;End the program
PROGRAM:
OUTPUT :
How many times to be executed 3
1. Even or Odd
2 Palindrome
3. Sum of digits
Enter the choice 1
Enter the number 2
given number is even
1. Even or Odd
2 Palindrome
3. Sum of digits
enter the choice 2
enter the number 121
the given number is palindrome
1. Even or Odd
2 Palindrome
3. Sum of digits
enter the choice 3
enter the number 456
sum of digits is: 15.
Ex.No:17
Date:
AIM:To develop a program that finds out whether a tank is overflowing or not wrt the
shape of the tank, its dimensions and rate of flow.
ALGORITHM:
STEP 1: Assume tank of shape rectangular, cylindrical or any other shape. Assume its
dimensions also.
STEP 2: Calculate volume of the tank. For e.g. Assuming the tank is cylindrical, then *Vtank
=
h Where r radius of tank (m) Where h height of tank (m)
STEP 3: Calculate volume of liquid. V_liq = F x t Where F - rate of flow (m3 /min) Where
t
time taken (min)
STEP 4: Conditions If V_liq > V_tank Tank is Overflow If V_liq < V_tank Tank is not
Overflow
PROGRAM:
Vtank=%pi*r*r*h;
disp('Vtank:');
disp(Vtank);
Vliquid=F*t;
disp('Vliquid');
disp(Vliquid);
if Vliquid>Vtank then
disp('Tank is Overflow');
else
OUTPUT:
Enter the Value of Flow Rate: 10
Enter the time to fill the Tank: 2
Enter the Radius of the Tank: 3
Enter the Height of the Tank: 4
Vtank:
113.09734
Vliquid
20.
Tank is not Overflow
PROGRAM USING FUNCTIONS
Ex.No:18
Date:
AIM :
To write a program using functions
PROGRAM:
To compute a given function : To computer the expression : x3+3x2y+xy
function[z]=calc(x,y)
z=x^3+3*x^2*y+x*y
endfunction
a=input(enter a);
b=input(enter b);
c=input(enter c);
d=input(enter d);
e=calc(a,b);
f=calc(c,d);
disp(e);
disp(f);
OUTPUT:
Entera:2
Enterb:3
Enterc:4
Enterd:5
50.
324.
OUTPUT:
24
720
Date:
AIM:
To plot a simple graph, printing labels and grid box in Scilab.
ALGORITHM:
Step 1: Start the Scilab Software
Step 2: Get the input values from user
Step 3: Perform operation using corresponding values
Step 4: Display the graph
Step 5: Stop the program
OUTPUT:
2.Plot the curve given by equation y=sin(x), as x varies from 0 to 2pi. Also label the x-
and y- axes and provide a suitable title to the plot.
PROGRAM:
x=[0:0.1:2*%pi]';
plot2d(sin(x));
OUTPUT:
3.
Plot the graph for the table with dashed dotted red lines, marker type diamond, marker edge
color green, marker size = 12 and label the graph along with grid and box. Also plot the bar
chart and pie diagram for the data.
Solutions:
Ans 1)
Code:
year = [ 2008,2009,2010,2011,2012 ]
population = [ 65,72,74,76,84 ]
plot (year,population,'rd-','markeredgecolor','g','markersize',12);
Solution:
Code:
S3 = [4 0 16 5 1];
S3 = [4 0 16 5 1]; S3 = [4 0 16 5 1];
a = sum(S1)/5; a = sum(S1)/5;
c = sum(S3)/5; c = sum(S3)/5;
d = sum(S4)/5; d = sum(S4)/5;
e = sum(S5)/5; e = sum(S5)/5;
S = [a b c d e]; S = [a b c d e];
45
bar (S,'y'); pie (S);
46
5. Write a SciLab program using subplots
AIM
To write the SciLab program to use subplot
PROGRAM
f=input(enter freq);
a=input(enter amplitude);
t=0:0.01:2;
y=a*sin(2*%pi*f*t);
y1=a*cos(2*%pi*f*t);
y2=t;
47
RESULT: Thus the graph is plotted with label, grid box using 2D Graphical commands is
executed and output is verified successfully.
48
3D GRAPHICS
Ex.No :20
Date:
AIM:
To write a Scilab program using 3D Graphical Commands .
ALGORITHM:
Step 1: Start the Scilab Software
Step 2: Get the input values from user
Step 3: Perform operation using corresponding values
Step 4: Display the graph
Step 5: Stop the program
PROGRAM:
t=[0:0.3:2*%pi]';
z=sin(t)*cos(t');
plot3d(t,t,z);
OUTPUT:
RESULT: Thus the 3D graphical commands are plotted output is verified successfully.
49
Ex: No: 21
Date:
Codings:
50
handles.e3=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.1046875,0.4041667,0.2890625,0.0958333],'Relief','default','SliderStep',
[0.01,0.1],'String','enter date','Style','text','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','e3','Callback','')
handles.e4=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.1,0.2,0.2953125,0.0979167],'Relief','default','SliderStep',[0.01,0.1],'String','see the
day','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','e4','Callback','')
handles.ed1=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.6015625,0.8020833,0.2921875,0.0958333],'Relief','default','SliderStep',
[0.01,0.1],'String','y','Style','edit','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','ed1','Callback','')
handles.ed3=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.6046875,0.4,0.2875,0.0958333],'Relief','default','SliderStep',
[0.01,0.1],'String','d','Style','edit','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','ed3','Callback','')
//////////
// Callbacks are defined as below. Please do not delete the comments as it will be used in
coming version
//////////
functioned4_callback(handles)
y=eval(get(handles.ed1,'string'));
m=eval(get(handles.ed2,'string'));
d=eval(get(handles.ed3,'string'));
num=datenum(y,m,d);
[n,s]=weekday(num);
disp('u were born'+s)
set(handles.ed4,'string',(s));
endfunction
51
OUTPUT:
Result:
52
Ex.No: 20 Program on GUI (Simple Calulator)
Date:
Codings:
53
[0.103125,0.6,0.2359375,0.1041667],'Relief','default','SliderStep',[0.01,0.1],'String','enter y
value','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','e2','Callback','')
handles.e3=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.103125,0.4020833,0.2328125,0.0958333],'Relief','default','SliderStep',
[0.01,0.1],'String','result','Style','text','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','e3','Callback','')
handles.ed1=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.4984375,0.8041667,0.3,0.0979167],'Relief','default','SliderStep',
[0.01,0.1],'String','x','Style','edit','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','ed1','Callback','')
handles.ed2=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.5,0.5979167,0.2984375,0.1],'Relief','default','SliderStep',
[0.01,0.1],'String','y','Style','edit','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','ed2','Callback','')
handles.ed3=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-
1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',
[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-
1],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.5015625,0.4,0.29375,0.1],'Relief','default','SliderStep',
[0.01,0.1],'String','z','Style','pushbutton','Value',
[0],'VerticalAlignment','middle','Visible','on','Tag','ed3','Callback','ed3_callback(handles)')
//////////
// Callbacks are defined as below. Please do not delete the comments as it will be used in
coming version
//////////
functioned3_callback(handles)
x=eval(get(handles.ed1,'string'));
y=eval(get(handles.ed2,'string'));
z=x+y;
disp(z);
set(handles.ed3,'string',string(z));
endfunction
54
OUTPUT:
Result :
Thus the program on simple calculator is written and executed successfully in scilab.
PROJECT WORK
55