Search code examples
matlabintegral

integral error (first input argument must be function handle.)


I want to use an integral over a vector but I will see an error for sys_eff which is " First input argument is not function handle."
I will be glad to have your guide and thanks in advance. I should mention that all vectors have the same ize as 345600.

function [ P_loss,time_eff, sys_eff ] = final( Pmpp, Pl_inv, Pl_bat_inv, Pl_bat_r )

    j=length(Pmpp);
      for t=1:j;
          P_loss(t)= Pl_inv(t) + Pl_bat_inv(t) + Pl_bat_r(t);
          time_eff(t)= P_loss(t)/Pmpp(t);
      end
    sys_eff=integral(time_eff,0,345600);
    end

Solution

  • As from the error message, the first input you provided to the function integral (i.e. time_eff) is not a function handle, but a vector. If you want to make a numeric integral of the function use the function trapz

    sys_eff=trapz(t,time_eff)
    

    if t is your integration variable.