Rayleigh truncated distribution error

조회 수: 1 (최근 30일)
Ayah Aljaafreh
Ayah Aljaafreh 2021년 5월 18일
How can I fix the error in this code
a = 18 ;
b = 30 ;
mean_x = 13 ;
var_x = 20 ;
% sample space :
N = 1000 ;
x = linspace (a,b,N) ;
%rayleigh distribution
f = @(x) (2/((4 * var_x)/(4-pi)))(x) exp(-1*(((x).^2)/((4 * var_x)/(4-pi))) ;
% cumulative Rayleigh distribution :
F = @(x) integral(f,-inf,x);
% truncated Rayleigh distribution :
ft = @(x) ((F(x)-F(a))/(F(b)-F(a))) ;
% data points :
f_data = f(x) ; % Rayleigh distribution
ft_data = ft(x) ; % truncated distribution
% plot data points :
plot(f_data , x); % plotting Raileigh distribution hold on
plot(ft_data , x); % plotting truncated distribution hold off
% finding the equation for first:
m_1 = @(x) (ft(x)).*(x) ;
M_1 = integral (m_1,a,b)
% finding the equation for second moment:
m_2 = @(x) (ft(x)).*(x.^2) ;
M_2 = integral (m_2,a,b)
% finding the equation for third moment:
m_3 = @(x) (ft(x)).*(x.^3) ;
M_3 = integral (m_3,a,b)
% finding the equation for forth moment:
m_4 = @(x) (ft(x)).*(x.^4) ;
M_4 = integral (m_4,a,b)
% finding the equation for fifth moment:
m_5 = @(x) (ft(x)).*(x.^5) ;
M_5 = integral (m_5,a,b)
% finding the variance:
var_t = M_2 - (M_1).^2
% new limits :
A = a.^2 ;
B = b.^2 ;
% new sample space :
y = x.*(x);
% plot PDF :
plot(f(y),y);
% the first moment :
my_1 = @(y) (f(y)).*(y) ;
My_1 = integral (my_1,A,B)
%the second moment :
my_2 = @(y) (f(y)).*(y.^2) ;
My_2 = integral (my_2,A,B)
% the third moment :
my_3 = @(y) (f(y)).*(y.^3) ;
My_3 = integral (my_3,A,B)

답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by