Posted by *dow* on July 10, 2010, 3:21 am

*> On 7/9/2010 8:50 PM, Steve D wrote:*

*> > Are you talking the length along a parabolic curve? If you are, I know*

*> > there is an exact math solution to this one. It involves a curve*

*> > integral. I'm sure of it since I calculated it when I was in college. Of*

*> > course I can't remember how to do it any more, but if you find an*

*> > appropriate egghead I'm sure you can get the formula. If I was more*

*> > ambitious I'd try to re-fire those old neurons (it's been more than 20*

*> > years).*

*> Sigh - me too, except that I took the course 45 years ago, and my old*

*> textbook was ruined in a basement flooding 30 years ago.*

*> It should be a fairly simple definite integral, but I'm down to my last*

*> two neurons - one is for breathing and the other... I forget what the*

*> other one does. :)*

*> Between the time I finished the program and the time I posted here I*

*> visited Amazon and ordered a used copy of my old textbook (Abraham*

*> Schwartz's "Calculus and Analytic Geometry"). Perhaps it'll stick better*

*> the second time around.*

*> My iterative approach is to approximate the curve with straight line*

*> segments and sum their lengths. At each iteration I increase the number*

*> of segments by a factor of ten, and when the difference between*

*> successive approximations is less than or equal to the error threshold,*

*> the program outputs the sum and quits. On this old IBM PC the last*

*> non-zero difference (before running out of bits) was on the order of*

*> 10^-13 - which is probably close enough for most DIY work.*

*> > I remember using the calculation to make something resembling a*

*> > parabolic dish. Knowing the length along the parabolic curve I cut paper*

*> > into wedges that varied in width based on the length along the parabolic*

*> > curve. I taped the wedges together and got a dish.*

*> I suspect that project would have exceeded my attention span, but I did*

*> write a Z-80 program to control three lead screws to spin dishes from*

*> aluminum disks back in C- and K-band days.*

*> --*

*> Morris Doveyhttp://www.iedu.com/DeSoto/ *

I think the integral is:

*<integral> sqrt(1 + 4Ax^2 +4ABx + B^2) dx*
between whatever limits you want. Maybe I could have integrated it

analytically sometime back in the middle of the last century, but

nowadays I'd do like you did, and just program a computer to grind out

a numerical answer.

The paraboloid problem was a bit different. If f is the focal length,

then we can define k = 4f^2. The integral becomes:

*<integral> r.sqrt(k+r^2).(k-r^2) dr*
where r is the radius of the rim of the dish. The lower limit of the

integral is zero, but the upper limit is what we want to find in order

to make the value of the definite integral zero. Usually, we know the

limits and want to find the value of the integral. In this problem, we

know the value of the integral and one of the limits, and we want to

find the other limit. Writing a program that would would produce an

answer correct to ten significant digits in less than a human lifetime

was a bit of a challenge!

Fun stuff....

dow

Posted by *dow* on July 10, 2010, 11:18 pm

*> > On 7/9/2010 8:50 PM, Steve D wrote:*

*> > > Are you talking the length along a parabolic curve? If you are, I know*

*> > > there is an exact math solution to this one. It involves a curve*

*> > > integral. I'm sure of it since I calculated it when I was in college. Of*

*> > > course I can't remember how to do it any more, but if you find an*

*> > > appropriate egghead I'm sure you can get the formula. If I was more*

*> > > ambitious I'd try to re-fire those old neurons (it's been more than 20*

*> > > years).*

*> > Sigh - me too, except that I took the course 45 years ago, and my old*

*> > textbook was ruined in a basement flooding 30 years ago.*

*> > It should be a fairly simple definite integral, but I'm down to my last*

*> > two neurons - one is for breathing and the other... I forget what the*

*> > other one does. :)*

*> > Between the time I finished the program and the time I posted here I*

*> > visited Amazon and ordered a used copy of my old textbook (Abraham*

*> > Schwartz's "Calculus and Analytic Geometry"). Perhaps it'll stick better*

*> > the second time around.*

*> > My iterative approach is to approximate the curve with straight line*

*> > segments and sum their lengths. At each iteration I increase the number*

*> > of segments by a factor of ten, and when the difference between*

*> > successive approximations is less than or equal to the error threshold,*

*> > the program outputs the sum and quits. On this old IBM PC the last*

*> > non-zero difference (before running out of bits) was on the order of*

*> > 10^-13 - which is probably close enough for most DIY work.*

*> > > I remember using the calculation to make something resembling a*

*> > > parabolic dish. Knowing the length along the parabolic curve I cut paper*

*> > > into wedges that varied in width based on the length along the parabolic*

*> > > curve. I taped the wedges together and got a dish.*

*> > I suspect that project would have exceeded my attention span, but I did*

*> > write a Z-80 program to control three lead screws to spin dishes from*

*> > aluminum disks back in C- and K-band days.*

*> > --*

*> > Morris Doveyhttp://www.iedu.com/DeSoto/ *

*> I think the integral is:*

*> <integral> sqrt(1 + 4Ax^2 +4ABx + B^2) dx*

*> between whatever limits you want. Maybe I could have integrated it*

*> analytically sometime back in the middle of the last century, but*

*> nowadays I'd do like you did, and just program a computer to grind out*

*> a numerical answer.*

*> The paraboloid problem was a bit different. If f is the focal length,*

*> then we can define k = 4f^2. The integral becomes:*

*> <integral> r.sqrt(k+r^2).(k-r^2) dr*

*> where r is the radius of the rim of the dish. The lower limit of the*

*> integral is zero, but the upper limit is what we want to find in order*

*> to make the value of the definite integral zero. Usually, we know the*

*> limits and want to find the value of the integral. In this problem, we*

*> know the value of the integral and one of the limits, and we want to*

*> find the other limit. Writing a program that would would produce an*

*> answer correct to ten significant digits in less than a human lifetime*

*> was a bit of a challenge!*

*> Fun stuff....*

*> dow- Hide quoted text -*

*> - Show quoted text -*

I tried writing program to solve your problem. In 13 seconds, it got

an answer correct to only about seven digits. So I guess my 15-year

old 386 is way slower than whatever you're using.

Here's the program I used to solve the paraboloid problem, in QBasic:

DEFDBL A-Z

f = 1 ' focal length

dr = f / 100000 ' step size

d2 = dr / 2

k = 4 * f * f

t = 0

r = d2

DO

r2 = r * r

q = r * (k - r2) * SQR(k + r2)

t = t + q

r = r + dr

LOOP WHILE t > 0

r = r - d2 - dr * t / q

d = r * r / (4 * f)

a = ATN(r / (d - f)) * 45 / ATN(1)

PRINT "Focal length:"; f; "unit(s)"

PRINT "Depth of dish:"; d; "units"

PRINT "Radius of rim:"; r ; "units"

PRINT "Angular radius of rim, seen from focus:"; a; "degrees"

END

With the given values for f and dr, it gets results correct to ten

significant digits, but on my machine takes about ten minutes to do

it How long does it take on your computer?

dow

Posted by *Morris Dovey* on July 11, 2010, 4:34 pm

On 7/10/2010 6:18 PM, dow wrote:

*> With the given values for f and dr, it gets results correct to ten*

*> significant digits, but on my machine takes about ten minutes to do*

*> it How long does it take on your computer?*

I suspect that the long runtime is a result of (re)interpreting the

BASIC source code 100,000 times, rather than a slow processor.

I disposed of my BASIC interpreter not too long after Nick stopped

posting code, so I can't run your code as-is - but I transliterated to C

#include <stdio.h>

#include <math.h>

int main(void)

{ double f = 1; /* focal length */

double dr = f / 100000; /* step size */

double d2 = dr / 2;

double k = 4 * f * f;

double t = 0;

double r = d2;

double r2,q,d,a;

do

{ r2 = r * r;

q = r * (k - r2) * sqrt(k + r2);

t = t + q;

r = r + dr;

} while (t > 0);

r = r - d2 - dr * t / q;

d = r * r / (4 * f);

a = atan(r / (d - f)) * 45 / atan(1);

printf("Focal length: %G\n",f);

printf("Depth of dish: %G\n",d);

printf("Radius of rim: %G\n",r);

printf("Angular radius of rim, seen from focus %G degrees",a);

return 0;

}

then compiled and linked. When I ran the executable I got

*C:\usr\mrd\c> dow*
Focal length: 1

Depth of dish: 1.84781

Radius of rim: 2.71868

Angular radius of rim, seen from focus 72.6801 degrees

C:\usr\mrd\c>

in just under 5 seconds.

Not quite enough time to go for coffee :(

--

Morris Dovey

http://www.iedu.com/DeSoto/

Posted by *dow* on July 11, 2010, 5:32 pm

*> On 7/10/2010 6:18 PM, dow wrote:*

*> > With the given values for f and dr, it gets results correct to ten*

*> > significant digits, but on my machine takes about ten minutes to do*

*> > it How long does it take on your computer?*

*> I suspect that the long runtime is a result of (re)interpreting the*

*> BASIC source code 100,000 times, rather than a slow processor.*

*> I disposed of my BASIC interpreter not too long after Nick stopped*

*> posting code, so I can't run your code as-is - but I transliterated to C*

*> #include <stdio.h>*

*> #include <math.h>*

*> int main(void)*

*> { double f = 1; /* focal length */*

*> double dr = f / 100000; /* step size */*

*> double d2 = dr / 2;*

*> double k = 4 * f * f;*

*> double t = 0;*

*> double r = d2;*

*> double r2,q,d,a;*

*> do*

*> { r2 = r * r;*

*> q = r * (k - r2) * sqrt(k + r2);*

*> t = t + q;*

*> r = r + dr;*

*> } while (t > 0);*

*> r = r - d2 - dr * t / q;*

*> d = r * r / (4 * f);*

*> a = atan(r / (d - f)) * 45 / atan(1);*

*> printf("Focal length: %G\n",f);*

*> printf("Depth of dish: %G\n",d);*

*> printf("Radius of rim: %G\n",r);*

*> printf("Angular radius of rim, seen from focus %G degrees",a);*

*> return 0;*

*> }*

*> then compiled and linked. When I ran the executable I got*

*> C:\usr\mrd\c> dow*

*> Focal length: 1*

*> Depth of dish: 1.84781*

*> Radius of rim: 2.71868*

*> Angular radius of rim, seen from focus 72.6801 degrees*

*> C:\usr\mrd\c>*

*> in just under 5 seconds.*

*> Not quite enough time to go for coffee :(*

*> --*

*> Morris Doveyhttp://www.iedu.com/DeSoto/ *

Well, if you're happy with only six significant digits, you should

have been able to use a much larger value of dr, maybe f/100, which

would have cut your run time to about 0.005 seconds. Even in

interpreted BASIC on my machine, it takes much less than a second.

(I've just tried it.)

Here's the little program I wrote to solve your parabola-length

problem:

DEFDBL A-Z

' y = ax^2 + bx + c

' c is irrelevant

a = 2 ' example values

b = 3

ll = -2 ' lower limit

ul = 2 ' upper limit

n = 100000 ' number of steps

dx = (ul - ll) / n

d = a + a

t = 0

FOR x = ll + dx / 2 TO ul STEP dx

dd = d * x + b

t = t + SQR(1 + dd * dd)

NEXT

l = t * dx

PRINT "Length:"; l

END

Is that pretty much the same as you wrote?

Evaluating SQRs takes time. Doing many thousands of them takes a lot

of time. I suspect that's what's taking most of the time, in both your

implementations and mine.

I don't feel bad about using computers instead of doing "real"

integrations. If we'd had computers in the 1950s, we'd have used them

then too.

dow

Posted by *Morris Dovey* on July 11, 2010, 6:50 pm

On 7/11/2010 12:32 PM, dow wrote:

*> Well, if you're happy with only six significant digits, you should*

*> have been able to use a much larger value of dr, maybe f/100, which*

*> would have cut your run time to about 0.005 seconds. Even in*

*> interpreted BASIC on my machine, it takes much less than a second.*

*> (I've just tried it.)*

I'm even easier to please than that since I can't afford machining to

tighter tolerances than +/-0.0002" (roughly +/-0.005mm).

With a tweak to the output format specification (%G -> %12.10f) the code

produces

Focal length: 1.0000000000

Depth of dish: 1.8478097550

Radius of rim: 2.7186833247

Angular radius of rim, seen from focus 72.6801340944 degrees

in the same time. The C language provides for a "long double" floating

point representation, but I can't imagine actually needing that kind of

precision for any real-world parabolic reflector.

*> Here's the little program I wrote to solve your parabola-length*

*> problem:*

*> DEFDBL A-Z*

*> ' y = ax^2 + bx + c*

*> ' c is irrelevant*

*> a = 2 ' example values*

*> b = 3*

*> ll = -2 ' lower limit*

*> ul = 2 ' upper limit*

*> n = 100000 ' number of steps*

*> dx = (ul - ll) / n*

*> d = a + a*

*> t = 0*

*> FOR x = ll + dx / 2 TO ul STEP dx*

*> dd = d * x + b*

*> t = t + SQR(1 + dd * dd)*

*> NEXT*

*> l = t * dx*

*> PRINT "Length:"; l*

*> END*

*> Is that pretty much the same as you wrote?*

Sorta close - mine won't produce any cumulative error if the machine

isn't capable of exactly representing dx in the number of bits

available, but that's just a nit and easily fixed.

*> Evaluating SQRs takes time. Doing many thousands of them takes a lot*

*> of time. I suspect that's what's taking most of the time, in both your*

*> implementations and mine.*

That depends a lot on the underlying hardware and math library. Some

years back I wrote a floating point library for processors having only

integer operations and, to my surprise, square roots didn't require

significantly more processing than plain old division...

*> I don't feel bad about using computers instead of doing "real"*

*> integrations. If we'd had computers in the 1950s, we'd have used them*

*> then too.*

I did (a Bendix G-15), and I did - and never overcame my addiction to

ever-higher throughput. That's what motivated me to order a copy of my

old textbook - so I could get rid of the loop. :)

--

Morris Dovey

http://www.iedu.com/DeSoto/

> On 7/9/2010 8:50 PM, Steve D wrote:> > Are you talking the length along a parabolic curve? If you are, I know> > there is an exact math solution to this one. It involves a curve> > integral. I'm sure of it since I calculated it when I was in college. Of> > course I can't remember how to do it any more, but if you find an> > appropriate egghead I'm sure you can get the formula. If I was more> > ambitious I'd try to re-fire those old neurons (it's been more than 20> > years).> Sigh - me too, except that I took the course 45 years ago, and my old> textbook was ruined in a basement flooding 30 years ago.> It should be a fairly simple definite integral, but I'm down to my last> two neurons - one is for breathing and the other... I forget what the> other one does. :)> Between the time I finished the program and the time I posted here I> visited Amazon and ordered a used copy of my old textbook (Abraham> Schwartz's "Calculus and Analytic Geometry"). Perhaps it'll stick better> the second time around.> My iterative approach is to approximate the curve with straight line> segments and sum their lengths. At each iteration I increase the number> of segments by a factor of ten, and when the difference between> successive approximations is less than or equal to the error threshold,> the program outputs the sum and quits. On this old IBM PC the last> non-zero difference (before running out of bits) was on the order of> 10^-13 - which is probably close enough for most DIY work.> > I remember using the calculation to make something resembling a> > parabolic dish. Knowing the length along the parabolic curve I cut paper> > into wedges that varied in width based on the length along the parabolic> > curve. I taped the wedges together and got a dish.> I suspect that project would have exceeded my attention span, but I did> write a Z-80 program to control three lead screws to spin dishes from> aluminum disks back in C- and K-band days.> --> Morris Doveyhttp://www.iedu.com/DeSoto/