-2

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{:});
Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
cleveroid
  • 1
  • 2

2 Answers2

2

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)
thang
  • 3,466
  • 1
  • 19
  • 31
0

You have to define the function first:

f = inline ('(x.^3).*(sqrt.((x.^4)+1))'); % define function f(x) = (x^3)*(sqrt(x^4 + 1))
q = quad(f, 1, 8);  %evaluate integral

Then you can plot or do whatever you want with q.

Cheers!

wotann07
  • 390
  • 1
  • 2
  • 9