Finding limits such that integral achieves desired value
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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 个评论
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 Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!