N
nmukh1
Hey guys,
I'm trying to optimize a program that measures the length of a curve.
Suppose I define a function f and I have two bounds [a,b] and am trying
to find the arc length. The familiar calculus equation
/
| sqrt(1+f'(x)) dx provides us the arc length.
/
I'm trying to use C to numerically find the arc length.
float metric(float x2, float x1){
return sqrt(pow(f((x2-x1),2))+pow(f(x2)-f(x1),2));}
float lengthofcurve(float a, float b){
float delta=.000001;
float sum=0;
for(a;a<b;a+=delta){
sum+=metric(a,a+delta);
}
return sum;}
Metric computes the length of two points and returnes their distance.
My results so far have been with a high degree of error. Any
suggestions on making the algorithm more efficient?
Thanks
I'm trying to optimize a program that measures the length of a curve.
Suppose I define a function f and I have two bounds [a,b] and am trying
to find the arc length. The familiar calculus equation
/
| sqrt(1+f'(x)) dx provides us the arc length.
/
I'm trying to use C to numerically find the arc length.
float metric(float x2, float x1){
return sqrt(pow(f((x2-x1),2))+pow(f(x2)-f(x1),2));}
float lengthofcurve(float a, float b){
float delta=.000001;
float sum=0;
for(a;a<b;a+=delta){
sum+=metric(a,a+delta);
}
return sum;}
Metric computes the length of two points and returnes their distance.
My results so far have been with a high degree of error. Any
suggestions on making the algorithm more efficient?
Thanks