how to define an integral function

19 visualizaciones (últimos 30 días)
Saeid
Saeid el 6 de Sept. de 2018
Comentada: Aishwarya Kasarla el 1 de Abr. de 2023
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?

Respuesta aceptada

Torsten
Torsten el 6 de Sept. de 2018
fun=@(z)z.^2+3*z-1;
F=@(x)integral(fun,0,x);
F(10)
  5 comentarios
Saeid
Saeid el 7 de Sept. de 2018
I tried the following format but it didn't work:
tspan = [0 5];
y0 = 0;
[t,y] = ode45(@(t,y) DYDT(t,y) , tspan, y0);
plot(t,y,'-o')
function dydt=DYDT(t,y)
fun=@(z)z.^2+3*z-1;
dydt=@(y)integral(fun,0,y)
end
Aishwarya Kasarla
Aishwarya Kasarla el 1 de Abr. de 2023
Hey, I am also stuck with the same proble, did you find the solution? Can you please help me out with this?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by