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
44
45
46
47
48
49
|
//Example 1 Page 57
clc
clear
//defining the function
function y=C(x)
y=1.6*x+1.9
endfunction
disp('a)')
//for cost of 1-mile trip
x=1
y=C(x)//function calling
mprintf("1-mile trip %f dollars\n",y)
//for cost of 2-mile trip
x=2
y=C(x)//function calling
mprintf("2-mile trip %f dollars\n",y)
//for cost of 3-mile trip
x=3
y=C(x)//function calling
mprintf("3-mile trip %f dollars\n",y)
//so the cost of x-mile trip is
x=poly([1.9 1.6],'x','coeff')
disp(x)
//the cost function is sum of two terms is the variable cost that depends on x, and the other is fixed cost which is independent
disp('Cost=VariableCost + FixedCost')
disp('b)')
//cost of 40-mile trip is
x=40
y=C(x)
mprintf("the cost of 40-mile trip is %f dollars",y)//displaying the cost of 40-mile trip
disp('c)')
//to calculate the cost of second mile
x=1
c1=C(x)//function calling
x=2
c2=C(x)//function calling
cost=(c2-c1)//calculating the cost of second mile
mprintf("cost of second mile is %f dollars",cost)
disp('d)')
x=[0 1 2]
disp(x)
y=C(x)//function calling
disp(y)
plot(7,5,x,y,'blue')//plotting the graph
xtitle(' ','Miles','Dollars');
|