MATLAB: How to define an integral function

functionsintegral functionsintegrals

I want to define a function in the integral form
f(x)=integral(g(z), z=0, z=x)
as an example:
for which I wrote:
fun = @(z) z^2+3*z-1;
x=linspace(0,1,100);
y = integral(fun,0,@(x) x)
plot(x,y)
But Matlab returned the following error:
Error using integral (line 85)
A and B must be floating-point scalars.
Error in IntegralFunction (line 8)
y = integral(fun,0,@(x) x)
Is it possible at all to do this in Matlab?

Best Answer

fun=@(z)z.^2+3*z-1;
F=@(x)integral(fun,0,x);
F(10)