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

Convergence error for simple cases. #13

Open
mcanyucel opened this issue Jan 24, 2022 · 3 comments
Open

Convergence error for simple cases. #13

mcanyucel opened this issue Jan 24, 2022 · 3 comments

Comments

@mcanyucel
Copy link

Thank you for your work on this free library..
I was doing some tests before implementing it to my project, and I kept getting convergence error for simple quadratic functions.
For example, the code below finds the root 10 as expected:

		let x = 20;
		const fn = (x: number): number => Math.pow(x, 2);
		const fnParams = [x];

		try {
			const result = goalSeek({
				fn,
				fnParams,
				percentTolerance: 0.01,
				maxIterations: 1000,
				maxStep: 10,
				goal: 100,
				independentVariableIdx: 0
			});
			console.log("====root: " + result);
			console.log("====fn value: " + fn(result));
			
			
		} catch (e) {
			console.log("----" + e.message);
			
		}

But if I change the goal to 130, I get failed to converge error:

...
	goal: 130,
...

Any ideas or tips for quadratic or higher order polynomials?

@adam-hanna
Copy link
Owner

adam-hanna commented Jan 24, 2022

Interesting. It gets stuck in an infinite loop between -40 and 250.

EDIT - Decreasing the maxStep and increasing the maxIterations seems to solve it. Maybe the algo could be improved to account for that?

@mcanyucel
Copy link
Author

mcanyucel commented Jan 24, 2022

Indeed, setting maxStep to 0.1 solves with the default maxIterations for goal 130 or similar numbers for x^2. Maybe quadratic functions are more susceptible to bouncing back and forth for large steps due to their higher order terms? I am really not that fluent in numerical analysis stuff to offer a lot of help or insight, though :). Possibly decreasing the step size automatically if the result gets stuck bouncing (yeah, that was not a very technical sentence) might help.

@rohit-rai-0101rm
Copy link

I am working with react and have a result table.
i want to set element of last cell 0 .
please guide on the same

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

3 participants