Thread Subject: Solve equation with the unknown being inside a summation loop

Subject: Solve equation with the unknown being inside a summation loop

From: Alex

Date: 14 Oct, 2009 20:54:03

Message: 1 of 3

Hi.
I need to solve the following equation:

sum{ (a(i) - b ) ^ x } - c + d / x =0

where i=1 to 10, a, b, c, d are known constants and x is the unknown variable.

Normally one can use a loop to calculate the sum and then use fsolve.
But here x is inside the loop making things complicated.

Is there a way to solve the above equation?

Thanks and regards,
Alex

Subject: Solve equation with the unknown being inside a summation loop

From: Steven Lord

Date: 14 Oct, 2009 22:00:48

Message: 2 of 3


"Alex " <thzachara@yahoo.gr> wrote in message
news:hb5dpb$nco$1@fred.mathworks.com...
> Hi.
> I need to solve the following equation:
>
> sum{ (a(i) - b ) ^ x } - c + d / x =0
>
> where i=1 to 10, a, b, c, d are known constants and x is the unknown
> variable.
>
> Normally one can use a loop to calculate the sum and then use fsolve.
> But here x is inside the loop making things complicated.
>
> Is there a way to solve the above equation?
>
> Thanks and regards,
> Alex

That depends on the values of a, b, c, and d. The general procedure:

function [x, fh] = solveme
% Call this as:
%
% [x, fh] = solveme
%
% To check the residual:
%
% fh(x)
fh = @functionToSolve;
x = fsolve(fh, 1);

function y = functionToSolve(x)
a = linspace(0, 1, 10);
b = 0.5;
c = 2.2;
d = 4.45;
y = -c+(d/x);
y = y + sum((a-b).^x);

If you don't want to hard-code your variables into the objective function,
see Q4.13 in the newsgroup FAQ (linked in my signature.) You might also
want to replace x in your equations with (x.^2+eps(x.^2)) to avoid trying to
divide by a negative number or raise an element of (a-b) to a nonpositive
power.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Solve equation with the unknown being inside a summation loop

From: Nasser Abbasi

Date: 14 Oct, 2009 22:00:38

Message: 3 of 3


"Alex " <thzachara@yahoo.gr> wrote in message
news:hb5dpb$nco$1@fred.mathworks.com...
> Hi.
> I need to solve the following equation:
>
> sum{ (a(i) - b ) ^ x } - c + d / x =0
>
> where i=1 to 10, a, b, c, d are known constants and x is the unknown
> variable.
>
> Normally one can use a loop to calculate the sum and then use fsolve.
> But here x is inside the loop making things complicated.
>
> Is there a way to solve the above equation?
>
> Thanks and regards,
> Alex

May be you can sum the loop symbolically and then at the end add the -c+d/x
and then use a root finding algorithm to look for roots? (do not use solve
on this).

a=rand(10,1); b=7; c=9; d=2;
syms x mysum
mysum=0;

for i=1:length(a)
    mysum=mysum+(a(i) - b )^x; %- c + d / x
end

mysum = mysum - c + d/x;

mysum = vpa(mysum)

(-6.7141609811796261197969215572812)^x
+ (-6.6483404929370033542568307893816)^x
+ (-6.6195541530246435613094035943504)^x
+ (-6.4502763917088605793992428516503)^x
+ (-6.4321783592747792113186733331531)^x
+ (-6.4147359088472759580668025591876)^x
+ (-6.2462709057215048957800718198996)^x
+ (-6.2427997708892783990108910074923)^x
+ (-6.1691713721037091389121087559033)^x
+ (-6.0828063361701900646494323154911)^x
+ 2.0/x - 9.0

example, there is root 1332.77+i 807.135 near x=1 and 1.47+i 0.937 near 2
etc...using the above data..

--Nasser

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
solve Alex 14 Oct, 2009 16:59:03
equation Alex 14 Oct, 2009 16:59:03
summation Alex 14 Oct, 2009 16:59:03
rssFeed for this Thread

Contact us at files@mathworks.com