Solving an equation with a summation
Show older comments
I am trying to solve the following equation for
all other variables are known and k is the current loop value.
I am currently trying to use fsolve but it reachings its stoping critiera as soon as it begins.
fun = @(Lambda) cumsum(Pk - abs((ak./(Lambda + Tk))-((Ik+Pn)/(abs(hkk).^2))))
Lambda = fsolve(fun,0)
The output is shown below.
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
Equation solved at initial point.
fsolve completed because the vector of function values at the initial
point is near zero as measured by the value of the function tolerance,
and the problem appears regular as measured by the gradient.
<stopping criteria details>
Lambda = 0
8 Comments
Star Strider
on 9 Apr 2021
Choose an initial estimate for ‘Lambda’ that is something other than the trivial solution.
Even:
Lambda = fsolve(fun,1)
is likely to be an improvement, although experiment with different initial estimates to see what works best.
Adam
on 9 Apr 2021
Star Strider
on 9 Apr 2021
Every value less than eps (which on my machine is 2.220446049250313e-16), is essentially 0 in operations involving addition or subtraction.
I was thinking of something like:
Lambda = fsolve(fun,1)
or:
Lambda = fsolve(fun,42)
or something sufficiently distant from 0 as to be easily distinguishable from it in the computation.
Adam
on 9 Apr 2021
Star Strider
on 9 Apr 2021
The rest of your code is invisible, so I’m left to guess as to what the other variables are. My guess is that they are vectors, and that the code sums them and then attempts to estimate ‘Lambda’.
If they are, this is essentially curve-fitting, and fsolve may not be the correct optimisation function.
Adam
on 9 Apr 2021
Star Strider
on 9 Apr 2021
I have no idea.
I have to take your word that the rest of the code actually exists, however I continue to believe that this is curve-fitting, and that an appropriate curve-fitting function would be preferable to fsolve for this task.
Adam
on 9 Apr 2021
Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!