<div>Sorry for the misunderstanding.</div>
<div> </div>
<div>To use fsolve, you need to have as many relations as variables, which is not the case with your test.</div>
<div> </div>
<div>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.</div>
<div> </div>
<div>Éric.</div>
<div> </div>
<div>PS: by the way the error message is not as speaking as it should be...</div>
<div> </div>
<div> </div>
<div><span class="gmail_quote">2008/3/14, Jerry Wang <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:jerrwang@yahoo.com" target="_blank">jerrwang@yahoo.com</a>>:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif">
<p>Thanks Eric,</p>
<p> </p>
<p>But what do you mean defining x0 inside vs outside? The func_for_fsolve function is declaired as </p>
<p><span> function [y] = func_for_fsolve ( x0 )<br></span>and the caller provides the x0 as an vector into it... </p><span>
<p> [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);</p>
<p> </p></span>
<p>Should be okay right?</p>
<p> </p>
<p>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?</p><span>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/test_fsolve.sci.txt" target="_blank" rel="nofollow"><span><font color="#810081">http://www.imagingspot.com/scilab/test_fsolve.sci.txt</font></span></a></div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/test_fsolve_caller.sce.txt" target="_blank" rel="nofollow"><span><font color="#810081">http://www.imagingspot.com/scilab/test_fsolve_caller.sce.txt</font></span></a></div>
<p> </p></span>
<p>Jerry</p>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif"><br><br>
<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><span>----- Original Message ----<br>From: Eric Dubois <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:grocer.toolbox@gmail.com" target="_blank">grocer.toolbox@gmail.com</a>><br>
To: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:users@lists.scilab.org" target="_blank">users@lists.scilab.org</a><br></span>
<div><span>Sent: Thursday, March 13, 2008 2:16:49 PM<br>Subject: Re: [scilab-Users] Solving multi-variable function<br><br>I cannot run your function because you do not provide the function ABSPredictor. But, if your function <span>func_for_fsolve.sci </span>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. <br>
<br>Eric.<br><br>
<div><span class="gmail_quote">2008/3/13, Jerry Wang <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:jerrwang@yahoo.com" target="_blank" rel="nofollow">jerrwang@yahoo.com</a>>:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<p>Oh, sorry, somehow the website doesn't like the .sci extension. Please see it here:</p>
<p><u><font color="#996699"><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></font></u><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.imagingspot.com/scilab/" target="_blank" rel="nofollow"></a></p>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">Yes, I provided initial values to the 4 variables. The "caller" function has:</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">chdir('C:\MyScilab');<br>getf('ABSPredictor.sci')<span><br>getf('func_for_fsolve.sci');<br></span>tic();<br>
ret_age=60;<br>mu_tree=36000;<br>delta_t=0.85;<br>sigma_b=0.50;<span><br>[x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);<br></span>time_length=toc()<br>beep(); <br> <br> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">When debugging, the func_for_fsolve does fine for the first iteration. Then it gives that error at the end of the first iteration.</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div><span>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">Jerry</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><br> </div></span>
<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><span>----- Original Message ----<br>From: Eric Dubois <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:grocer.toolbox@gmail.com" target="_blank" rel="nofollow">grocer.toolbox@gmail.com</a>><br>
To: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:users@lists.scilab.org" target="_blank" rel="nofollow">users@lists.scilab.org</a><br></span>
<div><span>Sent: Thursday, March 13, 2008 12:46:42 PM<br>Subject: Re: [scilab-Users] Solving multi-variable function<br><br>Unfortunately, the function is not available at the provided address...<br><br>Did you provide values to ret_age, mu_tree, delta_t, sigma_b, in order to feed the optimization program?<br>
<br>Eric.<br><br><br>
<div><span class="gmail_quote">2008/3/13, Jerry Wang <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:jerrwang@yahoo.com" target="_blank" rel="nofollow">jerrwang@yahoo.com</a>>:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">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:</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">!--error 98<br> variable returned by scilab argument function is incorrect</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">--------------------------------------</div>I add the function into the scope via:</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">--------------------------------------</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> getf('func_for_fsolve.sci');</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">--------------------------------------</div>I call the function via:</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">--------------------------------------</div> [x_result,v,info]=fsolve([ret_age, mu_tree, delta_t, sigma_b],func_for_fsolve);</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">--------------------------------------</div>Inside func_for_solve I have:</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">--------------------------------------</div>function [y] = func_for_fsolve ( x0 )<br>...</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">ret_age = round(x0(1));<br>mu_tree = x0(2);<br>delta_t = x0(3);<br>sigma_b = x0(4);</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">...</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">[statistical_sustainable] = ABSPredictor(mc,now_age,ret_age,mu_tree,delta_t,sigma_b);</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">...</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">y = abs(statistical_sustainable(index)./100 - 0.90);</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">...</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">y = y + penalties;</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">disp('testing123');<br>disp('testing234');</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">endfunction</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><br>--------------------------------------</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">--------------------------------------</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><br>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:</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">!--error 98<br> variable returned by scilab argument function is incorrect</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div></div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">Thank you!</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">Jerry</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">ps. the complete func_for_fsolve.sci is uploaded here for your viewing:</div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><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</a></div>
<div><span>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><br> </div>
<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- Original Message ----<br>From: Eric Dubois <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:grocer.toolbox@gmail.com" target="_blank" rel="nofollow">grocer.toolbox@gmail.com</a>><br>
To: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:users@lists.scilab.org" target="_blank" rel="nofollow">users@lists.scilab.org</a><br>Sent: Thursday, March 13, 2008 5:41:21 AM<br>Subject: Re: [scilab-Users] Solving multi-variable function<br>
<br>
<div>Fsolve takes one variable input, but the input can be a vector of any size.</div>
<div> </div>
<div>So, collapse your 4 variables into a single vector and adapt your fonction accordingly.</div>
<div> </div>
<div>Eric.<br><br> </div>
<div><span class="gmail_quote">2008/3/13, Jerry Wang <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:jerrwang@yahoo.com" target="_blank" rel="nofollow">jerrwang@yahoo.com</a>>:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif">
<div>Hello Scilab-ers,</div>
<div> </div>
<div>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.</div>
<div> </div>
<div>Any thoughts? Thanks!</div>
<div> </div><span>
<div>Jerry</div></span></div><br><span>
<hr size="1">
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.</a></span></div>
</blockquote></div><br> </div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><br> </div></span></div></div><span><br>
<hr size="1">
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.</a> </span></div></blockquote>
</div><br></span></div></div>
<div style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif"><br> </div></div>
<div><span><br>
<hr size="1">
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.</a></span></div>
</div></blockquote></div><br></span></div></div><br> </div></div>
<div><span><br>
<hr size="1">
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.</a></span></div>
</div></blockquote></div><br>