필터 지우기
필터 지우기

Can I make a ' y=k*x^n ' distribution by makedist() ?

조회 수: 2 (최근 30일)
Tamura Kentai
Tamura Kentai 2019년 7월 29일
댓글: Tamura Kentai 2019년 7월 30일
Hi, :
Thank you at first.
I hope to have the relation when loglog(x, y) plot , there will be a straight line, I know the math equation 'y=k*x^n' will make it, since ' log10(y) = log10(k) + n*log10(x)'. So that, if given x = 0:1e-3:1, equally spaced steps (linear), then plot the loglog(x,y), the line will be straight with a slope=n, offset=log10(k).
The question is how to use it with griddedInterpolant() & makedist() ?
t=[1:10];
t2=t'*10;
t=t';
f_base=[t,t2];
f_base
Fitp = griddedInterpolant(f_base(:,1),f_base(:,2),'linear','none');
x=f_base(:,1)*1.1;
lin_y=Fitp(x);
pd = makedist('exponential');
exp_y = pdf(pd,x);
plot(x, lin_y);
loglog(x,exp_y);
plot(x,log(exp_y));
I found the most similar is using makedist('exponential') with 'method' = 'exponential', which has the relation y=1/e*exp(1-x), if take log() with both side, log10(y) = log10(1/e) + (1 - x)*log10(e), here the log(y) won't be linear to log(x), it's linear to 'x' only.
So, may I ask, how to have a logarithm to logarithm relations between the griddedInterpolant() points (steps) or makedist() probability density function ?
I need to specify some points for 'bin' search in an array which x value (indexing) is in linear, but the search result (returned 'y' vs. x) I hope it has the log-log relation.
Can you help to give some hint how to do this ?
Thank you very much.
Best regards.
  댓글 수: 2
Tamura Kentai
Tamura Kentai 2019년 7월 29일
Hi, :
I am sorry, the previous message possibly is not clear enough.
So, I post another code to describe the detail, the plot(log(t), log(g)) shows a straight line in loglog plane, but plot(log(x),log(y)) doesn't, is there any method to do it ? With interpolate (not linear) into two points.
Thank you very much.
% log_interpolate.m
t=[1:10];
g=1e1*t.^5;
f_base=[t', g'];
x = 1:1e-3:10;
Fitp = griddedInterpolant(f_base(:,1),f_base(:,2),'linear','none');
y=Fitp(x);
plot(x,y);
plot(log(x),log(y));
plot(log(t),log(g));
Tamura Kentai
Tamura Kentai 2019년 7월 30일
Hi, :
I tried squeeze more points into the indexing array using for loop. Try making it more approx to a straight line in log-log plane.
But no matter whether using griddedInterpolant() or interp1(), I got error message as pasted in the bottom of the code frame.
I'm sorry, I really don't know what's happening. Could you help ?
Thank you very much.
t=[1:10];
g=1e1*t.^5;
t_ex = [];
g_ex = [];
% n: define the numbers of sampling points between two major terminal of trace.
n = 1e1;
for idx = 1:max(size(t)) - 1
t_expnd = logspace( log10( t(idx) ),log10( t(idx+1) ) ,n );
t_ex = [t_ex, t_expnd];
g_expnd = logspace( log10( g(idx) ),log10( g(idx+1) ) ,n );
g_ex = [g_ex, g_expnd];
end
f_base=[t_ex', g_ex'];
x = 1:1e-3:10;
% Fitp = griddedInterpolant(f_base(:,1),f_base(:,2),'linear','none');
% y=Fitp(x);
y = interp1(f_base(:,1),f_base(:,2),x);
% plot(x,y);
plot(log(x),log(y));
% plot(log(t),log(g));
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 191)
F = griddedInterpolant(X,V,method);
Error in thinking_loglog_interpolate_2 (line 24)
y = interp1(f_base(:,1),f_base(:,2),x);

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Classification에 대해 자세히 알아보기

제품


릴리스

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by