0
votes

I have two simple functions in two separate files like below:

function [thetavals postvals] = opt_compute_posterior(joint, theta_min, theta_max, num_steps)
    thetavals = linspace(theta_min, theta_max, num_steps); 
    postvals = joint(thetavals);
    postvals = postvals / ( sum(postvals) .* ( (theta_max - theta_min)/num_steps ));
end

function joint = plJoint(tobs) 
    gamma = 2.43; 
    joint = @(theta)( ( 1 ./ (theta.^(gamma + 1)) ) .* (tobs < theta) );

end

When I test this code with opt_compute_posterior(plJoint, 0, 300, 1000), I have error of "Not enough input arguments.", and I cannot find where the hell is wrong with the codes. Please lit me a light.

1
What does which opt_compute_posterior return? - hbaderts
@hbaderts It returns thetavals and postvals, which are some intervals and Riemann approximation of the joint function - noclew
As per the error message, you don't have enough input arguments. You need opt_compute_posterior(plJoint(you_need_an_input_here), 0, 300, 1000). - Phil Goddard

1 Answers

2
votes

It looks like you are trying to pass plJoint as a function handle to opt_compute_posterior. But if you just write plJoint, MATLAB interprets that as a function call and treats it as if you had written plJoint(). To indicate that you want a function handle, you need the @ symbol:

opt_compute_posterior(@plJoint, 0, 300, 1000)

EDIT:

It seems I had mistaken the intent of the original code. plJoint already returns a function handle, and you did intend to call it from the command window. In that case, you need to pass it a value for tobs when you call it, i.e.

opt_compute_posterior(plJoint(0.1), 0, 300, 1000)