|
"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
|