September 25, 2022, 11:27:19 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Polynomial evaluation

Started by GWS, December 03, 2019, 04:59:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

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
Tomorrow may be too late ..

Egil

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....
Support Amateur Radio  -  Have a ham  for dinner!

GWS

Hi Egil,

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

All the best, :)

Graham
Tomorrow may be too late ..

LarryMc

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.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

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
Tomorrow may be too late ..

billhsln

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
When all else fails, get a bigger hammer.