Integral with limit variable
조회 수: 92 (최근 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
채택된 답변
Torsten
2024년 1월 14일
편집: Torsten
2024년 1월 14일
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
추가 답변 (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!