Domanda

I calculate this integral.

integral(@(x) f, xmin, xmax);

At x = a, f(a) = constant and the integral(@(x) constant, xmin, xmax) returns errors.

So,

  1. How can I make this work at x = a.
  2. How to detect if the function returns constant?
È stato utile?

Soluzione

this will solve the problem:

fun = @(x) 5;
integral(fun,0,1,'ArrayValued',true)

according to Mathworks: Array-valued function flag, specified as the comma-separated pair consisting of 'ArrayValued' and either false, true, 0, or 1. Set this flag to true when you want to integrate over an array-valued function. The shape of fun(x) can be a vector, matrix, or N-D array.

Example: 'ArrayValued',true indicates that the integrand is an array-valued function.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top