how to manage fzero output
2 views (last 30 days)
Show older comments
This is a beginner's question.
I am using particle swarm optimization (PSO). The fzero function analyzes the values assigned by PSO in the objective function. Sometimes, however, the values assigned by PSO violate the input limits of fzero, which interrupts the process.
Is there a way to manage the output of fzero through optimoptions or optimset?
0 Comments
Accepted Answer
John D'Errico
on 9 Aug 2025
Edited: John D'Errico
on 9 Aug 2025
I'd argue you are thinking about this the wrong way.You see that fzero has a problem, so you think you need to do something to fzero. But that is wrong, the wrong approach.
You CAN constrain the parameters in the PSO however! Nothing stops you from doing that. Why do you need to use optimoptions? (Which would be of absolutely no use anyway.) Note that particleswarm does allow bound constraints on the parameters.
help particleswarm
If you are using some other tool, and you never told us, then you are on your own, since we cannot know what the capabilities of some unknown tool would be.
Finally, you have code that calls fzero. Surely you can pretest the parameters just before you call fzero. If the parameter would cause a problem, then do not call fzero, and just return some large value for the objective for that set of parameters. Again, there is absolutely no problem. All it takes is an if statement to test the value, BEFORE fzero is ever called.
And even if all of the above ideas don't seem to work for you (which they absolutely must, but assuming they don't) then you could call fzero using a try/catch clause to catch the times when fzero would fail.
Do you see that instead of looking at fzero, you need to think about how to deal with the problem before fzero ever sees it as an issue.
I've outlined 4 different solutions you can use. One of them will work for you. Actually, ALL of them should work.
0 Comments
More Answers (0)
See Also
Categories
Find more on Particle Swarm 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!