Finding limits such that integral achieves desired value

14 visualizaciones (últimos 30 días)
RPatel
RPatel el 22 de Nov. de 2017
Comentada: John D'Errico el 23 de Nov. de 2017
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 :)

Respuesta aceptada

Alan Weiss
Alan Weiss el 22 de Nov. de 2017
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

Más respuestas (1)

John D'Errico
John D'Errico el 22 de Nov. de 2017
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 comentarios
RPatel
RPatel el 22 de Nov. de 2017
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 el 23 de Nov. de 2017
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?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by