<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263149</link>
    <title>MATLAB Central Newsreader - Solve equation with the unknown being inside a summation loop</title>
    <description>Feed for thread: Solve equation with the unknown being inside a summation loop</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 14 Oct 2009 20:54:03 -0400</pubDate>
      <title>Solve equation with the unknown being inside a summation loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263149#687069</link>
      <author>Alex </author>
      <description>Hi.&lt;br&gt;
I need to solve the following equation:&lt;br&gt;
&lt;br&gt;
sum{ (a(i) - b ) ^ x } - c + d / x =0&lt;br&gt;
&lt;br&gt;
where i=1 to 10, a, b, c, d are known constants and x is the unknown variable.&lt;br&gt;
&lt;br&gt;
Normally one can use a loop to calculate the sum and then use fsolve. &lt;br&gt;
But here x is inside the loop making things complicated.&lt;br&gt;
&lt;br&gt;
Is there a way to solve the above equation?&lt;br&gt;
&lt;br&gt;
Thanks and regards,&lt;br&gt;
Alex</description>
    </item>
    <item>
      <pubDate>Wed, 14 Oct 2009 22:00:48 -0400</pubDate>
      <title>Re: Solve equation with the unknown being inside a summation loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263149#687079</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Alex &quot; &amp;lt;thzachara@yahoo.gr&amp;gt; wrote in message &lt;br&gt;
news:hb5dpb$nco$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hi.&lt;br&gt;
&amp;gt; I need to solve the following equation:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; sum{ (a(i) - b ) ^ x } - c + d / x =0&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; where i=1 to 10, a, b, c, d are known constants and x is the unknown &lt;br&gt;
&amp;gt; variable.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Normally one can use a loop to calculate the sum and then use fsolve.&lt;br&gt;
&amp;gt; But here x is inside the loop making things complicated.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Is there a way to solve the above equation?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks and regards,&lt;br&gt;
&amp;gt; Alex&lt;br&gt;
&lt;br&gt;
That depends on the values of a, b, c, and d.  The general procedure:&lt;br&gt;
&lt;br&gt;
function [x, fh] = solveme&lt;br&gt;
% Call this as:&lt;br&gt;
%&lt;br&gt;
% [x, fh] = solveme&lt;br&gt;
%&lt;br&gt;
% To check the residual:&lt;br&gt;
%&lt;br&gt;
% fh(x)&lt;br&gt;
fh = @functionToSolve;&lt;br&gt;
x = fsolve(fh, 1);&lt;br&gt;
&lt;br&gt;
function y = functionToSolve(x)&lt;br&gt;
a = linspace(0, 1, 10);&lt;br&gt;
b = 0.5;&lt;br&gt;
c = 2.2;&lt;br&gt;
d = 4.45;&lt;br&gt;
y = -c+(d/x);&lt;br&gt;
y = y + sum((a-b).^x);&lt;br&gt;
&lt;br&gt;
If you don't want to hard-code your variables into the objective function, &lt;br&gt;
see Q4.13 in the newsgroup FAQ (linked in my signature.)  You might also &lt;br&gt;
want to replace x in your equations with (x.^2+eps(x.^2)) to avoid trying to &lt;br&gt;
divide by a negative number or raise an element of (a-b) to a nonpositive &lt;br&gt;
power.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
    <item>
      <pubDate>Wed, 14 Oct 2009 22:00:38 -0400</pubDate>
      <title>Re: Solve equation with the unknown being inside a summation loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263149#687080</link>
      <author>Nasser Abbasi</author>
      <description>&lt;br&gt;
&quot;Alex &quot; &amp;lt;thzachara@yahoo.gr&amp;gt; wrote in message &lt;br&gt;
news:hb5dpb$nco$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hi.&lt;br&gt;
&amp;gt; I need to solve the following equation:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; sum{ (a(i) - b ) ^ x } - c + d / x =0&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; where i=1 to 10, a, b, c, d are known constants and x is the unknown &lt;br&gt;
&amp;gt; variable.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Normally one can use a loop to calculate the sum and then use fsolve.&lt;br&gt;
&amp;gt; But here x is inside the loop making things complicated.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Is there a way to solve the above equation?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks and regards,&lt;br&gt;
&amp;gt; Alex&lt;br&gt;
&lt;br&gt;
May be you can sum the loop symbolically and then at the end add the -c+d/x &lt;br&gt;
and then use a root finding algorithm  to look for roots? (do not use solve &lt;br&gt;
on this).&lt;br&gt;
&lt;br&gt;
a=rand(10,1); b=7; c=9; d=2;&lt;br&gt;
syms x mysum&lt;br&gt;
mysum=0;&lt;br&gt;
&lt;br&gt;
for i=1:length(a)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mysum=mysum+(a(i) - b )^x; %- c + d / x&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
mysum = mysum - c + d/x;&lt;br&gt;
&lt;br&gt;
mysum = vpa(mysum)&lt;br&gt;
&lt;br&gt;
(-6.7141609811796261197969215572812)^x&lt;br&gt;
+ (-6.6483404929370033542568307893816)^x&lt;br&gt;
+ (-6.6195541530246435613094035943504)^x&lt;br&gt;
+ (-6.4502763917088605793992428516503)^x&lt;br&gt;
+ (-6.4321783592747792113186733331531)^x&lt;br&gt;
+ (-6.4147359088472759580668025591876)^x&lt;br&gt;
+ (-6.2462709057215048957800718198996)^x&lt;br&gt;
+ (-6.2427997708892783990108910074923)^x&lt;br&gt;
+ (-6.1691713721037091389121087559033)^x&lt;br&gt;
+ (-6.0828063361701900646494323154911)^x&lt;br&gt;
+ 2.0/x - 9.0&lt;br&gt;
&lt;br&gt;
example, there is root 1332.77+i 807.135  near x=1 and 1.47+i 0.937 near 2 &lt;br&gt;
etc...using the above data..&lt;br&gt;
&lt;br&gt;
--Nasser </description>
    </item>
  </channel>
</rss>

