MATLAB: Finding limits such that integral achieves desired value

fzerointintegrallimitssolve

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 🙂

Best Answer

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