Finding limits such that integral achieves desired value
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 :)
0 commentaires
Réponse acceptée
Alan Weiss
le 22 Nov 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
Plus de réponses (1)
John D'Errico
le 22 Nov 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 commentaires
John D'Errico
le 23 Nov 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?
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!