summaryrefslogtreecommitdiff
path: root/1415/CH1/EX1.1.3/ex3.sce
diff options
context:
space:
mode:
Diffstat (limited to '1415/CH1/EX1.1.3/ex3.sce')
-rw-r--r--1415/CH1/EX1.1.3/ex3.sce43
1 files changed, 43 insertions, 0 deletions
diff --git a/1415/CH1/EX1.1.3/ex3.sce b/1415/CH1/EX1.1.3/ex3.sce
new file mode 100644
index 000000000..e8362ff3b
--- /dev/null
+++ b/1415/CH1/EX1.1.3/ex3.sce
@@ -0,0 +1,43 @@
+//Example 3 Page 48
+clc
+clear
+//defining the function
+function y=f(x)
+if(x >= -4 & x < -1) then//check value of x
+y=-1;
+elseif(x >= -1 & x <= 1) then//check value of x
+y=x;
+elseif(x > 1 & x <= 2) then//check value of x
+y=x^2-1;
+end
+endfunction
+
+disp('a)')
+x=-2;//assigning value to x
+y=f(x)//function calling
+disp(y)
+x=-1;//assigning value to x
+y=f(x)//function calling
+disp(y)
+x=0;//assigning value to x
+y=f(x)//function calling
+disp(y)
+x=1;//assigning value to x
+y=f(x)//function calling
+disp(y)
+x=2;//assigning value to x
+y=f(x)//function calling
+disp(y)
+
+disp('b)')
+x=[-4 -3 ]//assigning values to x
+y=f(x)//function calling
+disp(y)
+plot(4,4,x,y,'green')//plotting on graph
+x=[-1 0 1]//assigning values to x
+y=f(x)//function calling
+plot(4,4,x,y,'red')//plotting on graph
+x=[1.1 1.3 1.5 2]//assigning values to x
+y=f(x)//function calling
+plot(4,4,x,y,'blue')//plotting on graph
+xtitle('','x','y');