summaryrefslogtreecommitdiff
path: root/764/CH2/EX2.1.b/solution2_1.sce
blob: ab892e3cbf561ae12b1fbfd917eb8f94c3e885e7 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

//Obtain path of solution file
path = get_absolute_file_path('solution2_1.sce')
//Obtain path of data file
datapath = path + filesep() + 'data2_1.sci'
//Clear all
clc
//Execute the data file
exec(datapath)
//Calculate weightage points for all materials
//U - Ultimate tensile strength, H - Hardenability index, C - Cost
//Store the summations of each category in Uweigh, Hweigh and Cweigh respectively
Uweigh = 0
Hweigh = 0
Cweigh = 0
for i = 1:1:4
    Uweigh = Uweigh + U(i)
    Hweigh = Hweigh + H(i)
    Cweigh = Cweigh + (C(i)^(-1))
end
//Store percent strength for each material in Uper, Hper and Cper arrays according to respective categories
//Store points for each material in Up, Hp and Cp arrays according to respective categories
for i = 1:1:4
    Uper(i) = U(i)/Uweigh
    Up(i) = Uper(i) * Uw
    Hper(i) = H(i)/Hweigh
    Hp(i) = Hper(i) * Hw
    Cper(i) = (C(i)^(-1))/Cweigh
    Cp(i) = Cper(i) * Cw
end
//Store total points for each material in t array
for i = 1:1:4
    t(i) = Up(i) + Hp(i) + Cp(i)
end
//Print result table. Refer Table 2.14 on page 53
printf('\n\t|Material Property\t|Low alloy steel\t|Plain carbon steel\t|Stainless steel\t|Chromium steel\n')
printf('\na)\tTensile Strength')
printf('\n\tPer cent')
for i = 1:1:4
    printf('\t\t%0.3f\t',Uper(i))
end
printf('\n\tPoints')
for i = 1:1:4
    printf('\t\t\t%0.3f',Up(i))
end
printf('\n\nb)\tHardenability')
printf('\n\tPer cent')
for i = 1:1:4
    printf('\t\t%0.3f\t',Hper(i))
end
printf('\n\tPoints')
for i = 1:1:4
    printf('\t\t\t%0.3f',Hp(i))
end
printf('\n\nc)\tCost')
printf('\n\tPer cent')
for i = 1:1:4
    printf('\t\t%0.3f\t',Cper(i))
end
printf('\n\tPoints')
for i = 1:1:4
    printf('\t\t\t%0.3f',Cp(i))
end
printf('\n\n\tTotal Points')
for i = 1:1:4
    printf('\t\t%0.3f\t',t(i))
end
//Store all values of t in s array
for i = 1:1:4
    s(i) = t(i)
end
//Find the material with largest value of total points using s array
for i = 1:1:3
    if (s(i)>s(i+1)) then
        s(i+1) = s(i)
    end
end
//Largest value is obtained when i becomes 3 and the value is stored in s(i+1)
//Display the best material
choice = s(i+1)
if(choice == t(1))
    printf('\n\nLow alloy steel is the best material for the component\n')
    else if  (choice == t(2))
            printf('\n\nPlain carbon steel is the best material for the component\n')
    else if  (choice == t(3))
            printf('\n\nStainless steel is the best material for the component\n')
    else
            printf('\n\nChromium steel is the best material for the component\n')
end