-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedeain.m
76 lines (76 loc) · 1.51 KB
/
medeain.m
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
fprintf("\n");
choice = input( "Enter your choice:\n1:To calulate the discrete data mean enter 1:\n2:To calclulate frequency distribution observation mean enter 2:\n3:To calculate frequncy class distribution mean enter 3:");
switch choice
case 1
n=input("Enter the number of observations : ");
s=n/2;
b=mod(n,2);
fprintf("Enter the observations \n");
for i=1:n
fprintf("Enter x(%d):",i);
x(i)=input("");
z=sort(x);
end
if (b==0)
median=(z(s)+z(s+1))/2;
else
median=z(s+(1/2));
end
fprintf(" meadian = %d",median);
case 2
fprintf("\n");
n=input("Enter the number of observations : ");
fprintf("Enter the observations \n");
for i=1:n
fprintf("Enter x(%d):",i);
x(i)=input("");
fprintf("Enter f(%d):",i);
f(i)=input("");
end
cf(1)=f(1);
for i=2:n
cf(i)=cf(i-1)+f(i);
end
N=(cf(n)+1)/2;
pos=1;
for i=1:n
if cf(i)<N
pos=pos+1;
else
break;
end
end
fprintf("\n");
meadian=x(pos)
fprintf("Meadian=%f",meadian);
case 3
fprintf("\n");
n=input("Enter the number of class : ");
h=input("Enter the height of class : ");
l=input("Enter the first term : ");
l1(1)=l;
for i=1:n
fprintf("Enter f(%d):",i);
f(i)=input("");
end
for i=2:n
l1(i)=l1(i-1)+h;
end
cf(1)=f(1);
for i=2:n
cf(i)=cf(i-1)+f(i);
end
N=(cf(n))/2;
pos=1;
for i=1:n
if cf(i)<N
pos=pos+1;
else
break;
end
end
fprintf("%d",pos);
fprintf("\n");
meadian=l1(pos)+(((N)-cf(pos-1))/f(pos))*h;
fprintf("Meadian=%f",meadian);
end