Program Code
%Uniform Distributionclc;
close all;
clear all;
n=input('Input the end value of x = ');
a=input('Input the starting value of uniform distribution, a=');
b=input('Input the ending value of uniform distribution, b= ');
y=1/(b-a);
m=(a+b)/2;
s=((b-a)^2)/12;
disp('mean is ');m
disp('variance is ');s
disp('value of f(x) is ');y
u=[zeros(1,(a-1)) ones(1,(b-a)) zeros(1,(n-b))];
z=y*u;
stem(z);
axis([0 n 0 1]);
Example of Output
Input the end value of x = 10Input the starting value of uniform distribution, a=2
Input the ending value of uniform distribution, b= 8
mean is
m =
5
variance is
s =
3
value of f(x) is
y =
0.1667
______________________________
No comments:
Post a Comment
Please write your opinion about this MATLAB program here, only in English.