<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 27/01/2016 16:54, fujimoto2005 a
écrit :<br>
</div>
<blockquote cite="mid:1453910075986-4033345.post@n3.nabble.com"
type="cite">
<pre wrap="">The feature of my f(x) defined for x>0 is as follows.
f(x)<0 for x<x1
f(x1)=0
f(x) >0 for x1<x<x2
f(x)=0 for x>=x2
'fsolver' gives some x such as x>x2 as a solution.
I want to get x1 as a solution.
--
View this message in context: <a class="moz-txt-link-freetext" href="http://mailinglists.scilab.org/fsolver-tp4033340p4033345.html">http://mailinglists.scilab.org/fsolver-tp4033340p4033345.html</a>
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
A quick and dirty way of finding the minimum norm solution is to use
lsqrsolve and to penalize the residual with the squared norm of the
solution, like in this example (find one of the two closest to zero
solution of cos(x)=0) :<br>
<br>
<pre style="font-family:Monospaced;font-style:normal;font-size:17.0;"><span style="color:rgb(176,24,19);">function</span> <span style="color:rgb(131,67,16);font-weight:bold;">res</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);text-decoration:underline;">f1</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(131,67,16);font-weight:bold;">res</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">cos</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(176,24,19);">endfunction</span>
<span style="color:rgb(176,24,19);">function</span> <span style="color:rgb(131,67,16);font-weight:bold;">res</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);text-decoration:underline;">f2</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-weight:bold;">m</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(131,67,16);font-weight:bold;">res</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(0,0,0);text-decoration:underline;">f1</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(218,112,214);">%eps</span><span style="color:rgb(92,92,92);">^</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(92,92,92);">/</span><span style="color:rgb(188,143,143);">4</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">*</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(74,85,219);">]</span>
<span style="color:rgb(176,24,19);">endfunction</span>
format(20)
<span style="color:rgb(74,85,219);">[</span><span style="color:rgb(0,0,0);">x1</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">v</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">info</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">fsolve</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">0</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);text-decoration:underline;">f1</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(50,185,185);">disp</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">x1</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(74,85,219);">[</span><span style="color:rgb(0,0,0);">x2</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">v</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">info</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">lsqrsolve</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">0</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);text-decoration:underline;">f2</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(74,85,219);">[</span><span style="color:rgb(0,0,0);">x1</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">v</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">info</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">fsolve</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">x2</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);text-decoration:underline;">f1</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(50,185,185);">disp</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">x1</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(50,185,185);"></span>But the main problem is the tuning of the penalization parameter. But when it works well, you can then start from x2, hoping that you are in the basin of attraction of your solution.
</pre>
<br>
S.<br>
<br>
<pre class="moz-signature" cols="72">--
Département de Génie Informatique
EA 4297 Transformations Intégrées de la Matière Renouvelable
Université de Technologie de Compiègne - CS 60319
60203 Compiègne cedex</pre>
</body>
</html>