Dynamically updating values in matrix in Simulink

5 次查看(过去 30 天)
I have implemented a Forgetting Factor based RLS method to find paramters dynamically and used parameters calculated at kth time index to find SOC through AHIF algorithm. Now, I want to vary forgetting factor dynamically too, and want to use Particle Swarm Optimization(PSO) to find optimal forgetting fator at kth index.
For these, I chose 51 particles(with initial values from 0.95 to 1 with equal spacings), and 51 iterations. So for every kth time index, the first iteration of PSO, it calculated cost function value of all the current values of 51 particles. So, I want to compare their errors to find group best and Personal best. So, is there any way I can store all 51 errors to find group best in simulink.
Help is appreciated.

回答(1 个)

Ayush
Ayush 2023-8-22
Yes, you can store all 51 errors in Simulink to find the group best in Particle Swarm Optimization (PSO). One way to achieve this is by using a vector or an array to store the errors for each particle at each iteration.
Here's a general outline of how you can store and update the errors in Simulink:
1. Create a vector or array with a size of 51 to store the errors for each particle. Let's call it `errorVector`.
2. At the beginning of each iteration, initialize `errorVector` with the current errors of all particles.
3. Inside the PSO loop, calculate the cost function value for each particle and update the corresponding element in `errorVector`.
4. After updating `errorVector`, you can use it to determine the group best by finding the minimum error value among all particles. You can use a MATLAB Function block in Simulink to perform this operation.
5. Additionally, you can store the personal best error for each particle in a separate vector or array. This can be updated whenever a particle finds a better solution. You can use a similar approach as above to store and update the personal best errors.
By storing all the errors for each particle at each iteration, you will be able to find the group best and personal best values in Simulink. Remember to update the personal best whenever a particle finds a better solution, and update the group best at the end of each iteration based on the values in `errorVector`.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Sensors and Transducers 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by