How to run a function

1 view (last 30 days)
ViniAlmeida
ViniAlmeida on 17 Aug 2015
Commented: Walter Roberson on 17 Aug 2015
Hello guys, I'm having some problems to how use this function. This function make a data fit to a binomial distribution.
function [sse, curve_x, curve_y] = binomfun(params, data_x, data_y)
N = params(1);
p = params(2);
n = params(3)
f0 = binopdf(0:N-1, N, p);
F0 = binocdf(0:N-1, N, p);
curve_y = n.*f0.*(1-F0).^(n-1);
data_points = length(data_x)*N;
new_x_range = 0:1/(data_points-1):1;
curve_x = 0:1/(N-1):1;
curve_y_interp = interp1(curve_x, curve_y, new_x_range);
data_y_interp = interp1(data_x, data_y, new_x_range);
if max(curve_y_interp) == 0
scale = 1;
else
scale = max(data_y_interp)/max(curve_y_interp);
end
curve_y_interp = scale*curve_y_interp;
curve_y = scale*curve_y;
error_vector = curve_y_interp - data_y_interp;
sse = sum(error_vector .^2);
function params_min = find_min(data_x, data_y, N_range, p_range, n_range)
sse_min = realmax;
params_min = [0,0,0];
for N = N_range
for p = p_range
for n = n_range
params = [N, p, n];
[sse, curve] = binomfun(params, data_x, data_y);
if sse < sse_min
sse_min = sse;
params_min = params;
end
end
end
end
I don't know who is data_x. I know that data_y is my data, my data have 668700 points between 0 and 1. The problem always is at interpolation part. But, the question is: Who is my input data scale (data_x)?

Answers (1)

Walter Roberson
Walter Roberson on 17 Aug 2015
What does your y(1) the value of ? Is it associated with, for example, a particular time or temperature? Is your y just a sequence of data, first point, second point, and so on? Are they equal intervals apart?
If you need to, you can use x = 1:length(y)
  5 Comments
ViniAlmeida
ViniAlmeida on 17 Aug 2015
Edited: Walter Roberson on 17 Aug 2015
function params_min = find_min(data_x, data_y, N_range, p_range, n_range)
I see now that I use this fuction and this function call the other binonfum, now, the problem is the interpolation. Because I use:
N_range = 50:250
p_range = 0.4:0.001:0.6
n_range = 1:4
data_y = vector 668700x1
data_x = data scale (I don't know)
how is data_X? pleease, This don't woork :((
Walter Roberson
Walter Roberson on 17 Aug 2015
data_x = (1:size(data_y,1)).';

Sign in to comment.

Categories

Find more on Descriptive Statistics 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!