Solving multi-variable function

classic Classic list List threaded Threaded
11 messages Options
Jerry Wang Jerry Wang
Reply | Threaded
Open this post in threaded view
|

Solving multi-variable function

Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
Eric Dubois Eric Dubois
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" target="_blank">Try it now.

Jerry Wang Jerry Wang
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

In reply to this post by Jerry Wang
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.




Never miss a thing. Make Yahoo your homepage.
Eric Dubois Eric Dubois
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
<a href="http://www.imagingspot.com/scilab/func_for_fsolve.sci" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.imagingspot.com/scilab/func_for_fsolve.sci
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Try it now.




Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Make Yahoo your homepage.

Jerry Wang Jerry Wang
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

In reply to this post by Jerry Wang

Oh, sorry, somehow the website doesn't like the .sci extension.  Please see it here:

http://www.imagingspot.com/scilab/func_for_fsolve.txt

 
Yes, I provided initial values to the 4 variables.  The "caller" function has:
 
chdir('C:\MyScilab');
getf('ABSPredictor.sci')
getf('func_for_fsolve.sci');
tic();
ret_age=60;
mu_tree=36000;
delta_t=0.85;
sigma_b=0.50;
[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
time_length=toc()
beep();  
 
When debugging, the func_for_fsolve does fine for the first iteration.  Then it gives that error at the end of the first iteration.
 
Jerry

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 12:46:42 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.




Never miss a thing. Make Yahoo your homepage.




Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
Jerry Wang Jerry Wang
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

In reply to this post by Jerry Wang
 
If you could please take a quick look at this test code for fsolve--  Am I declaring or calling something incorrectly?  Even with this simple test code I am getting error 98.  Thanks.
 
 
 
Jerry


----- Original Message ----
From: Jerry Wang <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 1:03:05 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Oh, sorry, somehow the website doesn't like the .sci extension.  Please see it here:

http://www.imagingspot.com/scilab/func_for_fsolve.txt

 
Yes, I provided initial values to the 4 variables.  The "caller" function has:
 
chdir('C:\MyScilab');
getf('ABSPredictor.sci')
getf('func_for_fsolve.sci');
tic();
ret_age=60;
mu_tree=36000;
delta_t=0.85;
sigma_b=0.50;
[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
time_length=toc()
beep();  
 
When debugging, the func_for_fsolve does fine for the first iteration.  Then it gives that error at the end of the first iteration.
 
Jerry

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 12:46:42 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.




Never miss a thing. Make Yahoo your homepage.




Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.



Never miss a thing. Make Yahoo your homepage.
Eric Dubois Eric Dubois
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

In reply to this post by Jerry Wang
I cannot run your function because you do not provide the function ABSPredictor. But, if your function func_for_fsolve.sci is exactly what is on your website, there are some oddities. In particular, you should not define x0 inside the function to maximise, but outside.

Eric.

2008/3/13, Jerry Wang <[hidden email]>:

Oh, sorry, somehow the website doesn't like the .sci extension.  Please see it here:

<a href="http://www.imagingspot.com/scilab/func_for_fsolve.txt" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.imagingspot.com/scilab/func_for_fsolve.txt<a href="http://www.imagingspot.com/scilab/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

 
Yes, I provided initial values to the 4 variables.  The "caller" function has:
 
chdir('C:\MyScilab');
getf('ABSPredictor.sci')
getf('func_for_fsolve.sci');
tic();
ret_age=60;
mu_tree=36000;
delta_t=0.85;
sigma_b=0.50;
[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
time_length=toc()
beep();  
 
When debugging, the func_for_fsolve does fine for the first iteration.  Then it gives that error at the end of the first iteration.
 
Jerry

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 12:46:42 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
<a href="http://www.imagingspot.com/scilab/func_for_fsolve.sci" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.imagingspot.com/scilab/func_for_fsolve.sci
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Try it now.




Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Make Yahoo your homepage.




Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Try it now.

Jerry Wang Jerry Wang
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

In reply to this post by Jerry Wang

Thanks Eric,

 

But what do you mean defining x0 inside vs outside?  The func_for_fsolve function is declaired as

      function [y] = func_for_fsolve ( x0 )
and the caller provides the x0 as an vector into it... 

      [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);

 

Should be okay right?

 

Also, are you able to run the simplified test_fsolve.sci and test_fsolve_caller.sce?  Do they work for you?  Or are you also getting error 98?

 

Jerry



----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 2:16:49 PM
Subject: Re: [scilab-Users] Solving multi-variable function

I cannot run your function because you do not provide the function ABSPredictor. But, if your function func_for_fsolve.sci is exactly what is on your website, there are some oddities. In particular, you should not define x0 inside the function to maximise, but outside.

Eric.

2008/3/13, Jerry Wang <[hidden email]>:

Oh, sorry, somehow the website doesn't like the .sci extension.  Please see it here:

http://www.imagingspot.com/scilab/func_for_fsolve.txt

 
Yes, I provided initial values to the 4 variables.  The "caller" function has:
 
chdir('C:\MyScilab');
getf('ABSPredictor.sci')
getf('func_for_fsolve.sci');
tic();
ret_age=60;
mu_tree=36000;
delta_t=0.85;
sigma_b=0.50;
[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
time_length=toc()
beep();  
 
When debugging, the func_for_fsolve does fine for the first iteration.  Then it gives that error at the end of the first iteration.
 
Jerry

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 12:46:42 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.




Never miss a thing. Make Yahoo your homepage.




Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.




Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
Eric Dubois Eric Dubois
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

Sorry for the misunderstanding.
 
To use fsolve, you need to have as many relations as variables, which is not the case with your test.
 
If you have less equations than variables, but your problem has one solution and only one (which is neither the case for your function test_fsolve), then use optim with the square of your initial function.
 
Éric.
 
PS: by the way the error message is not as speaking as it should be...
 
 
2008/3/14, Jerry Wang <[hidden email]>:

Thanks Eric,

 

But what do you mean defining x0 inside vs outside?  The func_for_fsolve function is declaired as

      function [y] = func_for_fsolve ( x0 )
and the caller provides the x0 as an vector into it... 

      [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);

 

Should be okay right?

 

Also, are you able to run the simplified test_fsolve.sci and test_fsolve_caller.sce?  Do they work for you?  Or are you also getting error 98?

<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/test_fsolve.sci.txt" target="_blank" rel="nofollow">http://www.imagingspot.com/scilab/test_fsolve.sci.txt
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/test_fsolve_caller.sce.txt" target="_blank" rel="nofollow">http://www.imagingspot.com/scilab/test_fsolve_caller.sce.txt

 

Jerry



----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 2:16:49 PM
Subject: Re: [scilab-Users] Solving multi-variable function

I cannot run your function because you do not provide the function ABSPredictor. But, if your function func_for_fsolve.sci is exactly what is on your website, there are some oddities. In particular, you should not define x0 inside the function to maximise, but outside.

Eric.

2008/3/13, Jerry Wang <[hidden email]>:

Oh, sorry, somehow the website doesn't like the .sci extension.  Please see it here:

<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/func_for_fsolve.txt" target="_blank" rel="nofollow">http://www.imagingspot.com/scilab/func_for_fsolve.txt<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/" target="_blank" rel="nofollow">

 
Yes, I provided initial values to the 4 variables.  The "caller" function has:
 
chdir('C:\MyScilab');
getf('ABSPredictor.sci')
getf('func_for_fsolve.sci');
tic();
ret_age=60;
mu_tree=36000;
delta_t=0.85;
sigma_b=0.50;
[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
time_length=toc()
beep();  
 
 
When debugging, the func_for_fsolve does fine for the first iteration.  Then it gives that error at the end of the first iteration.
 
Jerry

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 12:46:42 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/func_for_fsolve.sci" target="_blank" rel="nofollow">http://www.imagingspot.com/scilab/func_for_fsolve.sci
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" target="_blank" rel="nofollow">Try it now.

 

 


Never miss a thing. <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs" target="_blank" rel="nofollow">Make Yahoo your homepage.


 


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" target="_blank" rel="nofollow">Try it now.


 


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" target="_blank">Try it now.

Jerry Wang Jerry Wang
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

In reply to this post by Jerry Wang

Oh I see.  I was using fsolve incorrectly.  Thank you Eric.

 

Can you or someone give me an example of fsolve solving two or more variables with two or more equations?  This way I can use it correctly next time?  Thank you.

 

Jerry



----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Friday, March 14, 2008 1:53:06 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Sorry for the misunderstanding.
 
To use fsolve, you need to have as many relations as variables, which is not the case with your test.
 
If you have less equations than variables, but your problem has one solution and only one (which is neither the case for your function test_fsolve), then use optim with the square of your initial function.
 
Éric.
 
PS: by the way the error message is not as speaking as it should be...
 
 
2008/3/14, Jerry Wang <[hidden email]>:

Thanks Eric,

 

But what do you mean defining x0 inside vs outside?  The func_for_fsolve function is declaired as

      function [y] = func_for_fsolve ( x0 )
and the caller provides the x0 as an vector into it... 

      [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);

 

Should be okay right?

 

Also, are you able to run the simplified test_fsolve.sci and test_fsolve_caller.sce?  Do they work for you?  Or are you also getting error 98?

 

Jerry



----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 2:16:49 PM
Subject: Re: [scilab-Users] Solving multi-variable function

I cannot run your function because you do not provide the function ABSPredictor. But, if your function func_for_fsolve.sci is exactly what is on your website, there are some oddities. In particular, you should not define x0 inside the function to maximise, but outside.

Eric.

2008/3/13, Jerry Wang <[hidden email]>:

Oh, sorry, somehow the website doesn't like the .sci extension.  Please see it here:

http://www.imagingspot.com/scilab/func_for_fsolve.txt

 
Yes, I provided initial values to the 4 variables.  The "caller" function has:
 
chdir('C:\MyScilab');
getf('ABSPredictor.sci')
getf('func_for_fsolve.sci');
tic();
ret_age=60;
mu_tree=36000;
delta_t=0.85;
sigma_b=0.50;
[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
time_length=toc()
beep();  
 
 
When debugging, the func_for_fsolve does fine for the first iteration.  Then it gives that error at the end of the first iteration.
 
Jerry

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 12:46:42 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

 

 


Never miss a thing. Make Yahoo your homepage.


 


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.


 


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.




Looking for last minute shopping deals? Find them fast with Yahoo! Search.
Eric Dubois Eric Dubois
Reply | Threaded
Open this post in threaded view
|

Re: Solving multi-variable function

I do not personnaly use fsolve, but you have examples in the help file (help fsolve).

Eric

2008/3/14, Jerry Wang <[hidden email]>:

Oh I see.  I was using fsolve incorrectly.  Thank you Eric.

 

Can you or someone give me an example of fsolve solving two or more variables with two or more equations?  This way I can use it correctly next time?  Thank you.

 

Jerry



----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Friday, March 14, 2008 1:53:06 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Sorry for the misunderstanding.
 
To use fsolve, you need to have as many relations as variables, which is not the case with your test.
 
If you have less equations than variables, but your problem has one solution and only one (which is neither the case for your function test_fsolve), then use optim with the square of your initial function.
 
Éric.
 
PS: by the way the error message is not as speaking as it should be...
 
 
2008/3/14, Jerry Wang <[hidden email]>:

Thanks Eric,

 

But what do you mean defining x0 inside vs outside?  The func_for_fsolve function is declaired as

      function [y] = func_for_fsolve ( x0 )
and the caller provides the x0 as an vector into it... 

      [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);

 

Should be okay right?

 

Also, are you able to run the simplified test_fsolve.sci and test_fsolve_caller.sce?  Do they work for you?  Or are you also getting error 98?

<a href="http://www.imagingspot.com/scilab/test_fsolve.sci.txt" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.imagingspot.com/scilab/test_fsolve.sci.txt
<a href="http://www.imagingspot.com/scilab/test_fsolve_caller.sce.txt" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.imagingspot.com/scilab/test_fsolve_caller.sce.txt

 

Jerry



----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 2:16:49 PM
Subject: Re: [scilab-Users] Solving multi-variable function

I cannot run your function because you do not provide the function ABSPredictor. But, if your function func_for_fsolve.sci is exactly what is on your website, there are some oddities. In particular, you should not define x0 inside the function to maximise, but outside.

Eric.

2008/3/13, Jerry Wang <[hidden email]>:

Oh, sorry, somehow the website doesn't like the .sci extension.  Please see it here:

<a href="http://www.imagingspot.com/scilab/func_for_fsolve.txt" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.imagingspot.com/scilab/func_for_fsolve.txt<a href="http://www.imagingspot.com/scilab/" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

 
Yes, I provided initial values to the 4 variables.  The "caller" function has:
 
chdir('C:\MyScilab');
getf('ABSPredictor.sci')
getf('func_for_fsolve.sci');
tic();
ret_age=60;
mu_tree=36000;
delta_t=0.85;
sigma_b=0.50;
[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
time_length=toc()
beep();  
 
 
When debugging, the func_for_fsolve does fine for the first iteration.  Then it gives that error at the end of the first iteration.
 
Jerry

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 12:46:42 PM
Subject: Re: [scilab-Users] Solving multi-variable function

Unfortunately, the function is not available at the provided address...

Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to  feed the optimization program?

Eric.


2008/3/13, Jerry Wang <[hidden email]>:
I did attempt to collapse the 4 variables into a single vector array but I received an error after fsolve reaches the end of the first iteration.  The error is:
 
!--error 98
 variable returned by scilab argument function is incorrect
 
--------------------------------------
I add the function into the scope via:
--------------------------------------
    getf('func_for_fsolve.sci');
 
--------------------------------------
I call the function via:
--------------------------------------
    [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);
 
--------------------------------------
Inside func_for_solve I have:
--------------------------------------
function [y] = func_for_fsolve ( x0 )
...
ret_age = round(x0(1));
mu_tree = x0(2);
delta_t = x0(3);
sigma_b = x0(4);
...
[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);
...
y = abs(statistical_sustainable(index)./100 - 0.90);
...
y = y + penalties;
disp('testing123');
disp('testing234');
endfunction

--------------------------------------
--------------------------------------

I tried testing the code by reducing the supplied argument x0 into 1 scalar variable instead of the 4 scalar vector, and the function call worked.  That's why I went ahead and assumed that fsolve takes only one variables.  Can you see what I am doing wrong that's causing me to receive:
!--error 98
 variable returned by scilab argument function is incorrect
 
 
Thank you!
 
Jerry
 
ps. the complete func_for_fsolve.sci is uploaded here for your viewing:
<a href="http://www.imagingspot.com/scilab/func_for_fsolve.sci" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.imagingspot.com/scilab/func_for_fsolve.sci
 
 

 
----- Original Message ----
From: Eric Dubois <[hidden email]>
To: [hidden email]
Sent: Thursday, March 13, 2008 5:41:21 AM
Subject: Re: [scilab-Users] Solving multi-variable function

Fsolve takes one variable input, but the input can be a vector of any size.
 
So, collapse your 4 variables into a single vector and adapt your fonction accordingly.
 
Eric.

 
2008/3/13, Jerry Wang <[hidden email]>:
Hello Scilab-ers,
 
Can any one point me to the right direction?  I want to find the zero point of a function that has 4 variables.  I want scilab to solve for the values of the 4 variables that would give me a result = 0 for the answer.  I initially tried fsolve, but I discovered that fsolve only take one variable input.
 
Any thoughts?  Thanks!
 
Jerry


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Try it now.

 

 


Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Make Yahoo your homepage.


 


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Try it now.


 


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Try it now.




Looking for last minute shopping deals? <a href="http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Find them fast with Yahoo! Search.