summaryrefslogtreecommitdiff
path: root/1415/CH1/EX1.1.3/ex3.sce
blob: e8362ff3b4bc7099431782062dfd0f7dd0303080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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');