Search code examples
matlabintegral

Matlab and integrals calculation


Can someone help me and tell what is the problem? I have to calculate some integrals and I keep getting this errors.

Example:

quad('(x.^3)*(sqr.((x.^4)+1))',1,8)

??? Error using ==> inline.subsref at 14
Not enough inputs to inline function.

Error in ==> quad at 77
y = f(x, varargin{:});

Solution

  • Your function is wrong:

    (x.^3)*(sqr.((x.^4)+1)) 
    

    is not a legit function. sqr is not defined, and you can't * if x is a vector. Do you mean sqrt in place of sqr? And to fix the *, just use .* (element by element multiplication), but you already know that.

    It should be:

    (x.^3).*(sqrt((x.^4)+1)) 
    

    You can change your code to:

    quad(@(x)((x.^3).*(sqrt((x.^4)+1))),1,8)
    

    or

    quad('((x.^3).*(sqrt((x.^4)+1)))',1,8)