Integral with limit variable
90 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(3 个)
Anjaneyulu Bairi
2024-1-14
编辑:Anjaneyulu Bairi
2024-1-14
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 个评论
John D'Errico
2024-1-14
编辑:John D'Errico
2024-1-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!