"Goal Seek" from Excel in Javascript

M

Michal

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
 
G

Gregor Kofler

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's_method

Gregor
 
D

Dr J R Stockton

In comp.lang.javascript message <733f879c-e602-46dd-98aa-226d82210f4c@y3
8g2000hsy.googlegroups.com>, Fri, 16 May 2008 02:31:12, Michal
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.
 
M

Michal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top