Integral with limit variable
86 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Torsten
on 14 Jan 2024
Edited: Torsten
on 14 Jan 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 Comments
More Answers (3)
Anjaneyulu Bairi
on 14 Jan 2024
Edited: Anjaneyulu Bairi
on 14 Jan 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 Comments
John D'Errico
on 14 Jan 2024
Edited: John D'Errico
on 15 Jan 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 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!