double truncated data sample

2 次查看(过去 30 天)
Bashar AlHalaq
Bashar AlHalaq 2021-2-4
Hi,
I generate data x using the code :
clc;
clear;
eta=2;
beta=4;
theta=1;
T=1;
t1=0.1;
t2=0.9;
ni=[10 50 75 100 50];
for i=1:length(ni)
n=ni(i);
for t=1:T
x=generate_sample(n,eta,beta,theta);
f1=pdf_WP(sort(x),eta,beta,theta);
F=cdf_WP(sort(x),eta,beta,theta);
R_Real=1-F;
end
end
the function is:
function [x]=generate_sample(n,eta,beta,theta)
for i=1:n
u=rand;
x(i)=theta.*(1./eta.*(log(1/(1-u)))).^(1./beta);
end
How can I make doule truncate from t1 to t2 from x
with my best regurds

回答(1 个)

Jeff Miller
Jeff Miller 2021-2-4
This is pretty ugly, but I think will do what you asked for:
function [x]=generate_sample(n,eta,beta,theta,t1,t2)
% find the bounds on u corresponding to the desired
% bounds on t1 and t2
xFn = @(u) theta.*(1./eta.*(log(1/(1-u)))).^(1./beta);
u1 = fzero(@(x) xFn(x)-t1,[eps 1-eps]);
u2 = fzero(@(x) xFn(x)-t2,[eps 1-eps]);
for i=1:n
% Generate u's only within the bounds
u=u1 + (u2-u1)*rand;
x(i)=xFn(u);
end
end
  2 个评论
Bashar AlHalaq
Bashar AlHalaq 2021-2-8
编辑:Bashar AlHalaq 2021-2-24
thank you for response on my demand ,
but i neeed truncate the sample data range , the code above dont cutting the sample data range
with my best reguard.
Jeff Miller
Jeff Miller 2021-2-8
Sorry, I guess I don't understand what you want. Maybe a numerical example would help?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 State-Space Control Design and Estimation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by