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

2 views (last 30 days)
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 Comments
Tamura Kentai
Tamura Kentai on 30 Jul 2019
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);

Sign in to comment.

Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by