<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
If only the last constant changes, you can adapt the newton algo to
your particular case:<br>
<br>
function y=newton3(coeffs, expo, cste, x0, eps)<br>
y = zeros(cste);<br>
x = x0;<br>
dcoeffs = coeffs .* expo;<br>
dexpo = expo - 1;<br>
for i = 1:size(cste, "*")<br>
z = coeffs * (x .^ expo)' - cste(i);<br>
while abs(z) > eps<br>
x = x - z / (dcoeffs * (x .^ dexpo)');<br>
z = coeffs * (x .^ expo)' - cste(i);<br>
end<br>
y(i) = x;<br>
end<br>
endfunction<br>
<br>
in supposing that cste is a decreasing row of values (last found
root is used as starting value in Newton's algo).<br>
<br>
cste=10:-0.0001:0.1839;<br>
rs=newton3([0.403 60.5], [-0.121 -0.73],cste,1,1e-10);<br>
<br>
(around 2 secs on my computer)<br>
<br>
to check:<br>
deff('y=foo(x)','y=0.403*x.^(-0.121)+60.5*x.^(-0.73)')<br>
max(abs(foo(rs)-cste))<br>
<br>
C<br>
<br>
On 05/11/2012 16:35, Paul Carrico wrote:
<blockquote
cite="mid:000901cdbb6b$24365e10$6ca31a30$@carrico@free.fr"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"Préformaté HTML Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
color:black;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.PrformatHTMLCar
{mso-style-name:"Préformaté HTML Car";
mso-style-priority:99;
mso-style-link:"Préformaté HTML";
font-family:"Consolas","serif";
color:black;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:90442408;
mso-list-type:hybrid;
mso-list-template-ids:-1029937172 -1353948568 67895299 67895301 67895297 67895299 67895301 67895297 67895299 67895301;}
@list l0:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:-;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:Calibri;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">Hi
Calixte,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">Your
suggestion looks encouraging … I’ll have a deeper look on
that specific issue when all the aspects of my new project
will be bracketed ! Many thanks …<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">And
Yes:<o:p></o:p></span></p>
<p class="MsoListParagraph"
style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
style="color:#0070C0" lang="EN-US"><span
style="mso-list:Ignore">-<span style="font:7.0pt
"Times New Roman""> </span></span></span><!--[endif]--><span
style="color:#0070C0" lang="EN-US">The exponents are always
negative<o:p></o:p></span></p>
<p class="MsoListParagraph"
style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
style="color:#0070C0" lang="EN-US"><span
style="mso-list:Ignore">-<span style="font:7.0pt
"Times New Roman""> </span></span></span><!--[endif]--><span
style="color:#0070C0" lang="EN-US">The coefficients are
always positive<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">To
go ahead, in one aspect of the project, only the last
constant change (it won(t be the case in a second stage), I
mean :<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">0.403*X^(-0.121)
+ 60.5*X^(-0.73) </span><span
style="font-family:Wingdings;color:#0070C0" lang="EN-US">è</span><span
style="color:#0070C0" lang="EN-US"> always the same ==
constant !<o:p></o:p></span></p>
<p class="MsoNormal"><b><span style="color:#0070C0" lang="EN-US">–
0.1839</span></b><span style="color:#0070C0" lang="EN-US">
</span><span style="font-family:Wingdings;color:#0070C0"
lang="EN-US">è</span><span style="color:#0070C0"
lang="EN-US"> it changes … may be either positive or
negative in a first understanding<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">Imagine
I’ve a matrix (n x1) where reach line is independent from
the others, and where it’s necessary to solve such equation
… I’ve been thinking using a loop:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">For
i=1:n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">
Solve my non-linear equation<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">End<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">(n
from hundred thousand’s to million’s)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">It
may be interesting to slip that loop onto several processor
(solving by “blocks”), isn’t it ?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#0070C0" lang="EN-US">Paul<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">De :</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">
<a class="moz-txt-link-abbreviated" href="mailto:users-bounces@lists.scilab.org">users-bounces@lists.scilab.org</a>
[<a class="moz-txt-link-freetext" href="mailto:users-bounces@lists.scilab.org">mailto:users-bounces@lists.scilab.org</a>] <b>De la part
de</b> Calixte Denizet<br>
<b>Envoyé :</b> lundi 5 novembre 2012 16:10<br>
<b>À :</b> <a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a><br>
<b>Objet :</b> Re: [Scilab-users] root calculation<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hi Paul,<br>
<br>
If the exponent are always negative and the coefficients are
always positive, the function is strictly decreasing (so the
derivative is non-null), you can use a Newton method.<br>
<br>
function y=newton(fun, dfun, x0, eps)<br>
y=fun(x0)<br>
while abs(y) > eps<br>
x0 = x0 - y / dfun(x0);<br>
y = fun(x0)<br>
end<br>
y = x0;<br>
endfunction<br>
<br>
deff('y=foo(x)','y=0.403*x.^(-0.121)+60.5*x.^(-0.73)-0.1839')<br>
deff('y=dfoo(x)','y=0.403*-0.121*x.^(-1.121)+60.5*-0.73*x.^(-1.73)')<br>
<br>
To find a "good" starting point:<br>
If x is a solution then 0.403*x^(-0.121)<=0.1839 and
60.5*x^(-0.73)<=0.1839, so x
>=max((0.1839/0.403)^(-1/0.121), (0.1839/60.5)^(-1/0.73))<br>
<br>
newton(foo,dfoo,2806,1e-10)<br>
<br>
A faster way:<br>
function y=newton2(coeffs, expo, cste, x0, eps)<br>
y = coeffs * (x0 .^ expo)' - cste;<br>
dcoeffs = coeffs .* expo;<br>
dexpo = expo - 1;<br>
while abs(y) > eps<br>
x0 = x0 - y / (dcoeffs * (x0 .^ dexpo)');<br>
y = coeffs * (x0 .^ expo)' - cste;<br>
end<br>
y = x0;<br>
endfunction<br>
<br>
newton2([0.403 60.5], [-0.121 -0.73],0.1839,2806,1e-10)<br>
<br>
Calixte<br>
<br>
On 05/11/2012 13:13, Paul Carrico wrote: <o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Dear all,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">This a stupid question,
but how can I solve directly in, Scilab an equation such as
: </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">0.403*X^(-0.121) +
60.5*X^(-0.73) – 0.1839 = 0</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">?</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Is-it necessary to code
a function ? from memory : dichotomy method, secant method,
Brent one etc. …</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Regards</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Paul</span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:12.0pt;font-family:"Times New
Roman","serif""><br>
<br>
<br>
<o:p></o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>users mailing list<o:p></o:p></pre>
<pre><a moz-do-not-send="true" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a><o:p></o:p></pre>
<pre><a moz-do-not-send="true" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a><o:p></o:p></pre>
<p class="MsoNormal"><span
style="font-size:12.0pt;font-family:"Times New
Roman","serif""><br>
<br>
<br>
<o:p></o:p></span></p>
<pre>-- <o:p></o:p></pre>
<pre>Calixte Denizet<o:p></o:p></pre>
<pre>Software Development Engineer<o:p></o:p></pre>
<pre>-----------------------------------------------------------<o:p></o:p></pre>
<pre>Scilab Enterprises<o:p></o:p></pre>
<pre>143bis rue Yves Le Coz - 78000 Versailles, France<o:p></o:p></pre>
<pre><a moz-do-not-send="true" href="http://www.scilab-enterprises.com">http://www.scilab-enterprises.com</a><o:p></o:p></pre>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
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>
<br>
<br>
<pre class="moz-signature" cols="72">--
Calixte Denizet
Software Development Engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
<a class="moz-txt-link-freetext" href="http://www.scilab-enterprises.com">http://www.scilab-enterprises.com</a></pre>
</body>
</html>