• Please review our updated Terms and Rules here

Newton's method in QBASIC

nkeck72

Member
Joined
Jun 21, 2020
Messages
22
Location
Tennessee, USA
Some talk about the speed of math functions in Commodore BASIC in another thread inspired me to write a quick-and-dirty implementation of the calculus concept of Newton's method in QBASIC as a sort of benchmark for DOS PCs this morning. If you're not familiar, Newton's method is an algorithmic method for estimating zeroes (where a graph crosses the x-axis), and requires a guess as to where this occurs. The definition of this method is:

x[SUB]n+1[/SUB]=x[SUB]n[/SUB]-(f(x[SUB]n[/SUB])/f'(x[SUB]n[/SUB]))

where f(x) is the function you wish to find the zero of, x[SUB]n[/SUB] is the current guess, x[SUB]n+1[/SUB] is the calculated next guess, and f'(x) is the derivative of f(x).

Feel free to try it out and report back. This is by no means a good example of BASIC or QBASIC code and could probably use some optimization and cleanup, I only wrote this in about an hour or so. Everything uses double-precision internally to prevent precision loss so I'd be interested in particular to see the differences with and without an FPU installed.

Full disclosure, I wrote this in Windows 98 so I don't know how well this will run on a pre-286. YMMV. Feel free to direct me to another forum category if QBASIC doesn't run on a < 386.
 

Attachments

  • NEWTON.zip
    1.3 KB · Views: 3
A couple of random responses:

- This does more to benchmark BASIC implementations than it does to benchmark a system, unless you specify exactly which qbasic interpreter or compiler you wrote it for
- QBASIC runs on every system
- The version of QBASIC that comes with DOS 6 doesn't use floating-point IIRC -- I thought that was only a feature of the compilers, but I could be wrong
 
QBASIC supports floating point. It does not support math coprocessors though which was reserved for the compilers.
 
[quote Trixter]This does more to benchmark BASIC implementations than it does to benchmark a system, unless you specify exactly which qbasic interpreter or compiler you wrote it for[/quote]

Yeah, I guess that's what I meant. Sorry for the confusion. :)

[quote Trixter]QBASIC runs on every system
- The version of QBASIC that comes with DOS 6 doesn't use floating-point IIRC -- I thought that was only a feature of the compilers, but I could be wrong[/quote]

I didn't know QBASIC ran on everything, but the QBASIC that comes with DOS 6 definitely does use floating point, that's what I wrote it on.

[quote krebizfan]It does not support math coprocessors though which was reserved for the compilers.[/quote]

That I didn't know, but it does make sense I suppose. I have a copy of Borland C++ that hasn't seen some attention here recently, I might just fire it up and write an implementation in that and compile it specifically for benchmarking FPUs.
 
I didn't know QBASIC ran on everything, but the QBASIC that comes with DOS 6 definitely does use floating point, that's what I wrote it on.

Apologies to you and krebizfan; I meant that it doesn't support the 8087 math co-processor unless you're using a compiler, as krebizfan confirmed. All versions of Microsoft BASIC in all forms support floating-point routines.
 
Back
Top