Finding limits such that integral achieves desired value

조회 수: 14 (최근 30일)
RPatel
RPatel 2017년 11월 22일
댓글: John D'Errico 2017년 11월 23일
Hello,
I want to find the upper limit of an integral such that the desired value is obtained. I have found a way, but I would like to reduce computation time. Could you please suggest alternate functions/methods?
syms T upper_lim;
acc_indef = -2.5*T;
T0=solve(int(acc_indef,T,0,upper_lim)+5==0,upper_lim);
This is a simple integral whose upper limit is to be calculated such that the value of the integral is -5...
Thanks in advance :)

채택된 답변

Alan Weiss
Alan Weiss 2017년 11월 22일
I believe that you would probably save time by solving numerically with fzero rather than using symbolic math. For example, the second time I ran this code, I got the following timing information:
tic
fun = @(t)-2.5*t;
intfun = @(x)integral(fun,0,x) + 5;
xval = fzero(intfun,[0,10])
toc
xval =
2
Elapsed time is 0.017252 seconds.
You could probably make it even faster by setting appropriate options, such as a larger-than-default TolX tolerance for fzero.
Alan Weiss
MATLAB mathematical toolbox documentation

추가 답변 (1개)

John D'Errico
John D'Errico 2017년 11월 22일
Seriously?
syms T upper_lim;
acc_indef = -2.5*T;
vel = int(acc_indef,T,0,upper_lim)+5;
vel
vel =
5 - (5*upper_lim^2)/4
You are worried about the solve time? Are you needing to solve this that often? The solution is trivial.
upper_lim = +2 or -2
Do it once. WTP?
  댓글 수: 2
RPatel
RPatel 2017년 11월 22일
This was the easiest of the integrals I found which is a part of a bigger code... acc_indef (the function itself) changes over time and computation relatively takes time...
This is a part of the optimization problem in Model predictive control, which should ideally be computed in less than 0.1 sec, for realtime implementation (update rate of 10 Hz)...
So... yes... seriously... would you have any suggestions?
John D'Errico
John D'Errico 2017년 11월 23일
Of course I could have suggestions. But the fact is, you did not tell us the actual problem you had, or even imply that this was only a simple example. I could suggest lots of things that were wild overkill for a trivial problem. But why bother?
So, depending on the real problem, you MIGHT use fzero. You might do some of the algebra in advance, you might use some other solver. You MIGHT do lots of things.
Compute as much as you can once, up front. Use the most efficient tools. If you don't need symbolic precision, then why would you use symbolic tools?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by