473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

"Goal Seek" from Excel in Javascript

Does any one know how to create a function that works similar as "Goal
Seek" in Excel?

For example:
var a=8;
var b=6;
function c(a,b) {
return a*b;
}

And now I want that "c" will return me 56 and I want to do that only
by changing "b" and this "goal seek" function will return me solution
that "b" must be equal 7

I hope I didn't explain too chaotic.

I tried to find that on google but without any results.
Thanks in advance
Michael
Jun 27 '08 #1
3 10583
Michal meinte:
Does any one know how to create a function that works similar as "Goal
Seek" in Excel?

For example:
var a=8;
var b=6;
function c(a,b) {
return a*b;
}

And now I want that "c" will return me 56 and I want to do that only
by changing "b" and this "goal seek" function will return me solution
that "b" must be equal 7

I hope I didn't explain too chaotic.

I tried to find that on google but without any results.
Perhaps this for a start:

http://en.wikipedia.org/wiki/Newton%27s_method

Gregor

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Jun 27 '08 #2
In comp.lang.javascript message <733f879c-e602-46dd-98aa-226d82210f4c@y3
8g2000hsy.googlegroups.com>, Fri, 16 May 2008 02:31:12, Michal
<re****@gmail.composted:
>For example:
var a=8;
var b=6;
function c(a,b) {
return a*b;
}

And now I want that "c" will return me 56 and I want to do that only
by changing "b" and this "goal seek" function will return me solution
that "b" must be equal 7
Go to <URL:http://www.merlyn.demon.co.uk/js-demos.htm#FZ>, insert
in the textarea

function c(a,b) { return a*b; }
c(8, X) - 56

put Min X =, say, 0 and Max X = 50, press Find, and read the answer.

Then read the whole page, and View Source to find out how it is done :
it uses
function FindZero(F) { with (F) {
var j, X, XV, HV, LV, Fn = EX1.value
var Lo = userIn(Min1), Hi = userIn(Max1)
X = Lo ; LV = eval(Fn)
X = Hi ; HV = eval(Fn)
if ((LV*HV)>=0) { Ans1.value="Bad bounds" ; return }
for (j=0; j<40; j++) {
X = (Hi+Lo)/2 ; XV = eval(Fn) ; if (XV==0) break
if ((XV*LV)<0) { Hi = X ; HV = XV } else { Lo = X ; LV = XV }
}
Ans1.value="X = "+SigFigExp((Hi+Lo)/2, 8) } }
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 27 '08 #3
On 16 May, 23:27, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
>...
...
Thank you Dr J R Stockton.
Thats something what I was looking for.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
It's not that I didn't read. I just couldn't find.. Maybe because my
"question" was bad :)

Thanks again

Michael
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: | last post by:
Could some help m figure out to strip an unknown range of characters in a path between the first "/" and "/" found in a folder path somewhere on my site. eg: /catamaranco/sales/boat/1.asp eg:...
1
by: jphelan | last post by:
I ran a MS Access Analyzer program that suggested changing, "rst.FindFirst strcriteria" to using the, "Seek" instead. I tried making the change. I get a Compile error that says, "Argument is not...
5
by: jensen bredal | last post by:
I need to keep track on user "session data" while still turning session off as i do not want users login to expire? Thanks JB
0
by: Felix Finch | last post by:
I have a perl test program which has about 80 test cases, each of which creates its own schema so I can remove them with DROP SCHEMA xxx CASCADE. Normally each test case creates and drops the same...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
24
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.