This is an Active Origin Project - it uses a new feature of Origin 7.5 that allows attaching files to an OPJ. This OPJ has an Origin C file, a worksheet template, and a graph template attached to it.
How to find roots of equations:
-------------------------------
You need to issue a command from the script window, where you specify the equation and the x range in which to find roots. If roots are found for the equation in the specified x range, a graph of the equation is created and the roots are marked on the graph. A hidden worksheet is
also created that contains the data plotted in the graph. The roots are also reported to the script window.
For example, to find roots of the equation:
sin(x)/x = 0.1
in the x range of -10 to 10, enter the following command in the script window and press the Enter key:
find_roots "sin(x)/x-0.1" -10 10
Note that
1> The equation has to be written in the form f(x) = 0 and you then enter only the f(x) part in the command.
2> Only one variable is supported and it has to be named x.
3> The equation has to be entered with quotes around it.
4> In your equation, you can use any mathematical function that is part of the ANSI C function set, or is part of the Origin C function set. For example, there is no sec(x) in ANSI C. So you will need to write that as 1/cos(x).
Algorithm for finding roots:
----------------------------
This sample uses a very simple algorithm, as follows:
a> In the x range specified by user, all intervals that contain a sign change in the function are first located.
b> Each such interval is checked to see if the function is monotonic within that interval.
c> In each of the intervals where the function is monotonic, a bisectional root search is performed: The interval is successively divided in half until either the maximum number
of iterations is exceeded, or the root is found to a preset precision. The max iterations and root precision are set in the Origin C code as constants, and can be changed.
To view the code associated with this OPJ, go to
Code Builder (menu item: View|Code Builder) and look at the Origin C file called find_roots.c in the Project branch of the Code Builder workspace tree.