Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config Object rather than positional API #1

Closed
CrossEye opened this issue Oct 30, 2014 · 3 comments
Closed

Config Object rather than positional API #1

CrossEye opened this issue Oct 30, 2014 · 3 comments
Assignees

Comments

@CrossEye
Copy link

I like this idea quite a bit. But your API is a little... well, crowded might be a good word. I think that, rather than a positional parameter list, a configuration object would provide both more flexibility and better readability:

    goalSeek({
        testFunction: function(a, b, c) {return a * b * c;},
        goal: 140,
        params: [4, 5, 3],
        position: 2,
        tolerance: 0.01,     // optional
        maxIterations: 1000  // optional
    });
    //=> 7

    goalSeek({
        testFunction: function(i, o) {return i * o.a  o.b.b1;},
        goal: 140,
        params: [4, {a: 5, b: {b1: 3}}],
        position: 2,
        prop: "b.b1",        // optional
        tolerance: 0.01,     // optional
        maxIterations: 1000  // optional
    });
    //=> 7

The other thing I would suggest is that allow an undefined value as the starting choice for the target parameter. I know that this would make the algorithm harder to get off the ground; you'll have to go seeking for an appropriate initial value that works. But it could lead to a nicer user experience, using a token such as __ (which is not defined) as a placeholder:

    var __; // (undefined)
    //...
    goalSeek({
        testFunction: function(a, b, c) {return a * b * c;},
        goal: 140,
        params: [4, 5, __], 
        position: 2,
        tolerance: 0.01,     // optional
        maxIterations: 1000  // optional
    });
    //=> 7

Note the change to params. This makes it much clearer what you're looking for.

(I also posted this suggestion on comp.lang.javascript, where I first saw this.)

@adam-hanna
Copy link
Owner

Thanks for the suggestions! I'll definitely make the changes.

I'll also be extending the root method beyond the Steffenson model to include secant and a modified secant method.

@adam-hanna adam-hanna self-assigned this Oct 31, 2014
@CrossEye
Copy link
Author

CrossEye commented Nov 1, 2014

I'll be interested to see the extensions to other methods.

One thing I didn't say was that, at least for the simple parameter-position-only case (I'm not so sure about the object-property one), the __ as placeholder also should allow the user to skip the position parameter.

Very interesting work, in any case.

@adam-hanna
Copy link
Owner

Incorporated your ideas. Thanks for the input!

I'll add the secant root method asap (sometimes the steffenson method doesn't converge).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants