Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 20.5 ('Xojo Workflows')
Instant purchase and download via GumRoad!

FEATURE

Evaluating Equations with XojoScript

A simple alternative to parsing a user's equation

Issue: 20.5 (September/October 2022)
Author: Harris Ulery
Author Bio: Harris Ulery is a long-time Xojo user and xDev reader.
Article Description: No description available.
Article Length (in bytes): 27,046
Starting Page Number: 28
Article Number: 20504
Resource File(s):

Download Icon project-20504.zip Updated: 2022-08-31 23:28:44

Related Web Link(s):

me (
http://delaneyrm.com/Newton.html

Excerpt of article text...

Every now and then, I would like an application to be capable of evaluating an arbitrary function entered via the keyboard. Each time, the prospect of writing an equation parser was always more daunting than the need was pressing, so the notion was relegated to a lower priority. Recently, however, I was reviewing this magazine's articles on scripting with XojoScript. Marc Zeedar's 2007 xDev Magazine article (xdev#5612) illustrating the use of scripting to provide "plugin" filters for image processing, appeared to promise a simple mechanism to substitute for equation parsing.

I had made a few feeble attempts at scripting before, but never gotten anywhere and couldn't figure out why. Still, I was anxious to give it another try—this time with more conviction. Let's roll up the sleeves and make a tool to find the roots of a user-supplied function, f(x) = 0.

The Math

One common approach to this problem is the so-called Newtom-Raphson (N-R) method (see Wikipedia's article for a good discussion of this and related methods as well as their shortcomings). This scheme is an efficient iterative one that is easy to code. Starting with a guess (x0), a refined estimate (x1) is obtained as:

x1 = x0 - f(x0) / f'(x0) (1a)

...End of Excerpt. Please purchase the magazine to read the full article.