Integral with limit variable
87 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I know the problem is old and well known. However, I'm a beginer and I cannot solve it in my particular issue:
beta=2.1;
eta=1500;
t=0:5000;
R=exp(-(t./eta).^beta);
fun=@(t)exp(-(t./eta).^beta);
INT=integral(fun,0,t);
Error using integral
Limits of integration must be double or single scalars.
I have no idea how to solve this issue with returning the values of my function (fun) within a given range of t, not olny for single or double scalars. Is there any way?
0 comentarios
Respuesta aceptada
Torsten
el 14 de En. de 2024
Editada: Torsten
el 14 de En. de 2024
Note that t is at the same time integration variable and upper limit of the integral. That's confusing. You should rename one of these variables.
beta=2.1;
eta=1500;
t=0:5000;
fun=@(t)exp(-(t./eta).^beta);
INT=arrayfun(@(t)integral(fun,0,t),t)
plot(t,INT)
0 comentarios
Más respuestas (3)
Anjaneyulu Bairi
el 14 de En. de 2024
Editada: Anjaneyulu Bairi
el 14 de En. de 2024
Hi,
I understand that you are trying to solve integration problem, but facing errors with limits of integration. You can try below troubleshooting steps to resolve your query.
- The variable "t" is an array but this argument should be a scalar and if you want to find integration for every value in "t" from 0 , you can refer the below code .
beta=2.1;
eta=1500;
t=0:5000;
R=exp(-(t./eta).^beta);
fun=@(t)exp(-(t./eta).^beta);
for i=1:length(t); %loop on t
INT(i)=integral(fun,0,t(i));
end
- To plot between "t" and "INT", you can execute the below command
plot(t,INT);
- You can visit the MathWorks documentaion on integration for more information : https://in.mathworks.com/help/matlab/ref/integral.html
I hope it helps to resolve your query.
0 comentarios
John D'Errico
el 14 de En. de 2024
Editada: John D'Errico
el 15 de En. de 2024
Multiple ways to solve this. First the easy, just as a numerical integration using a trapeziodal rule.
beta=2.1;
eta=1500;
t=0:5000;
R=exp(-(t./eta).^beta);
Rint = cumtrapz(R);
plot(t,Rint)
INT cannot solve the problem in symbolic form. Oh well. I had a funny feeling int might have issues.
syms T
Rsym = exp(-(T./eta).^beta);
int(Rsym)
So we see that int gave up. But that does not mean we need to give up too. We can still solve the problem easily enough. Use ode45. Effectively, if we wish to integrate R from 0 to t, this is equivalent to solving the simple first order ODE, of the form
dy/dt = R(t) = exp(-(t./eta).^beta)
You should recognize this as a basic way to perform a cumulative integration. So set this up as an ODE, then apply ODE45 to the problem.
tspan = 0:5000;
y0 = 0;
odefun = @(t,y) exp(-(t./eta).^beta);
[Tout,Yout] = ode45(odefun,tspan,y0);
plot(Tout,Yout)
Again, quite easy to solve. Remember this trick when you need to perform a cumulative integration. Just because you see an integral sign in there, it does not mean you need to use integral or int.
0 comentarios
Ver también
Categorías
Más información sobre Symbolic Math Toolbox 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!