How can I plot the graph of a possibility distribution function?

28 Views Asked by At

I want to plot the graph of this possibility distribution function. I write the Matlab code. But it does not work. please help me. The Matlab codes are given below:

clear all
format long;
format compact;

h_2=0.9;
r_1=7;r_2=8;r_3=9;r_4=10;
x=0:20:1;

if r_1<=x<=((r_1+r_2)/2)
    mu_zeta=(1+h_2)*(x-r_1)/(r_2-r_1+h_2*(x-r_1));
end

if ((r_1+r_2)/2)<= x <= r_2
    mu_zeta=((1-h_2)*x-r_1+h_2*r_2)/(r_2-r_1+h_2*(r_2-x));
end

if r_3 <= x <= (r_3+r_4)/2
    mu_zeta=((-1+h_2)*x-(h_2*r_3)+r_4)/(r_4-r_3+h_2*(x-r_3));
end

if ((r_3+r_4)/2) <= x <= r_2
   mu_zeta=(1+h_2)*(r_4-x)/(r_4-r_3+h_2*(r_4-x));
end

plot(x,mu_zeta,'--R ','linewidth',1)
hold on;
1

There are 1 best solutions below

0
On

Be careful how you define x and the way use pointwise operations / vs ./ and * vs .* etc. This code produces a plot

clear all
format long;
format compact;

h_2=0.9;
r_1=7;r_2=8;r_3=9;r_4=10;
x=0:1:20;

if r_1<=x<=((r_1+r_2)/2)
    mu_zeta = (1+h_2).*(x-r_1)./(r_2-r_1+h_2.*(x-r_1));
end

if ((r_1+r_2)/2)<= x <= r_2
    mu_zeta=((1-h_2).*x-r_1+h_2*r_2)./(r_2-r_1+h_2.*(r_2-x));
end

if r_3 <= x <= (r_3+r_4)/2
    mu_zeta=((-1+h_2).*x-(h_2*r_3)+r_4)./(r_4-r_3+h_2.*(x-r_3));
end

if ((r_3+r_4)/2) <= x <= r_2
   mu_zeta=(1+h_2).*(r_4-x)./(r_4-r_3+h_2.*(r_4-x));
end

plot(x, mu_zeta,'--R ','linewidth',1)
hold on;

enter image description here