Search code examples
matlabfunctionintegral

New to MATLAB. Getting the error First input argument must be a function handle. While attempting to integrate current function


So this is what I have so far

t=60;

q=integral(e(t)*i(t), t, 0, 2*pi);

function v=e(t)

v=160*sin(t);

end

function c=i(t)

c=2*sin(t-(pi/6));

end

but it is returning the following errors and I have no idea how to fix it. I've looked at other posts referencing the same error and I haven't been able to fix it.

Error using integral (line 82)
First input argument must be a function handle.

Error (line 10)
q=integral(e(t)*i(t), t, 0, 2*pi);

Any help will be greatly appreciated


Solution

  • You should have something like this:

    e_times_i = @(t) e(t) .* i(t)
    q=integral(e_times_i, 0, 2*pi);
    

    Indeed, the first argument of integral matlab function handle. You gave value not the function handle.