IonicWind Software

Creative Basic => Console Programs => Topic started by: GWS on December 03, 2019, 04:59:16 PM

Title: Polynomial evaluation
Post by: GWS on December 03, 2019, 04:59:16 PM
Hi folks,

Here's an old computing method by IBM (Engineering Analysis for Computers - 1961).

This computes the value of a polynomial using only multiply and add operations ..

' Polynomial evaluation

openconsole
cls

def x,y:float

' To compute the value of a polynomial

' f(x) = ax^5 + bx^4 + cx^3 + dx^2 + ex + f
' simplify to

' f(x) = (((((a)x + b)x + c)x + d)x +e)x + f
' ie. by repeating the steps (multiply and add) ..

' Example:
print
print "Polynomial evaluation":print:print STRING$(25, "_" )
print:print


setprecision 10

x = 2.55

' direct evaluation ..
y = 2.1 * x^5 + 0.4 * x^4 + 32 * x^3 + 12.5 * x^2 + 0.34 * x + 100

print "Direct method using exponentiation and add"
print
print y

' alternatively ..
y = (((((2.1)*x + 0.4)*x + 32)*x + 12.5)*x + 0.34)*x + 100

print
print "Alternative method using only multiply and add"
print
print y


print:print:print
print "Press any key to exit .."

do:until inkey$<>""
closeconsole
end


Best wishes, :)

Graham
Title: Re: Polynomial evaluation
Post by: Egil on December 04, 2019, 03:03:23 AM
Thanks Graham,

We had a similar example when I first learnt to code in 1962 or 1963. I beleive the languag was called RPG.
The computer occupied most of the basement of a large office building, and when we had done the coding on paper sheets, the papers where then sent to some busy ladies, that punched the cards we fed the large IBC computer with.
Those were the days....
Title: Re: Polynomial evaluation
Post by: GWS on December 04, 2019, 08:57:13 AM
Hi Egil,

Yes it was an interesting time - we were very lucky to have experienced it.

All the best, :)

Graham
Title: Re: Polynomial evaluation
Post by: LarryMc on December 04, 2019, 09:24:59 AM
when I was going to nite school after I got out of the AF I remember having to take a semester of RPG and of COBOL. We had to punch our own cards and submit them. Then wait for them to be run on the same main frame that handle all the university business.
Title: Re: Polynomial evaluation
Post by: GWS on December 04, 2019, 11:30:02 AM
Hi Larry,

A stack of punched cards had to be carried with care - if you dropped them, your program statements could be shuffled.  ;D

Best wishes, :)

Graham
Title: Re: Polynomial evaluation
Post by: billhsln on December 04, 2019, 12:48:49 PM
Just FYI, I work on an iSeries (AS/400) machine, where I program in RPG and COBOL.  Both languages are still alive and running.  RPG was Report Program Generator, but now it is used like we used to use COBOL/CICS.  It has green screen entry screens, to enter data into and respond back from and will do batch report processing and file manipulation.  It also allows access to DB2 to use SQL.

Bill