Find limits satisfying a condition on an integral
I have some data that I have interpolated with even spacing from measured data. I can integrate this between defined limits etc using trapz. However, I want to turn the problem on its head and find for what limit does the result of definite integral satisfy a condition. As an example:
x = linspace(0, 2*pi, 20);
y = sin(x);
lowLimIndex = 1;
upLimIndex = find(x>pi,1);
halfInt = trapz(x(lowLimIndex:upLimIndex),y(lowLimIndex:upLimIndex))
Or close enough to the known result of 2… But in my case, I effectively want to find the value of x that results in the integral = 2.
I could fit an equation to my data and use solve to solve it in symbolic mode I suppose…. Seems there ought to be a way to do this using the optimization tools though?
Any help appreciated!I have some data that I have interpolated with even spacing from measured data. I can integrate this between defined limits etc using trapz. However, I want to turn the problem on its head and find for what limit does the result of definite integral satisfy a condition. As an example:
x = linspace(0, 2*pi, 20);
y = sin(x);
lowLimIndex = 1;
upLimIndex = find(x>pi,1);
halfInt = trapz(x(lowLimIndex:upLimIndex),y(lowLimIndex:upLimIndex))
Or close enough to the known result of 2… But in my case, I effectively want to find the value of x that results in the integral = 2.
I could fit an equation to my data and use solve to solve it in symbolic mode I suppose…. Seems there ought to be a way to do this using the optimization tools though?
Any help appreciated! I have some data that I have interpolated with even spacing from measured data. I can integrate this between defined limits etc using trapz. However, I want to turn the problem on its head and find for what limit does the result of definite integral satisfy a condition. As an example:
x = linspace(0, 2*pi, 20);
y = sin(x);
lowLimIndex = 1;
upLimIndex = find(x>pi,1);
halfInt = trapz(x(lowLimIndex:upLimIndex),y(lowLimIndex:upLimIndex))
Or close enough to the known result of 2… But in my case, I effectively want to find the value of x that results in the integral = 2.
I could fit an equation to my data and use solve to solve it in symbolic mode I suppose…. Seems there ought to be a way to do this using the optimization tools though?
Any help appreciated! definite integral, optimization MATLAB Answers — New Questions