fminsearch function stops after a few iterations in simulink real time with inverter
Mostra commenti meno recenti
Hello all,
I have a problem when running fminsearch in simulink in a real time application. I want to calculate the stress amplitude and the stress angle by fminsearch, so that the unbalance factor kU2, or the norm of kU2 and kU0 becomes as small as possible. These values are then to be passed to an inverter. A part of the code is shown here:
x0 = [u1_abs u1_phi]
fun2 = @(x)kU2kU0berechnung(x,u2,u3,din);
y = fminsearch(fun2,x0);
function meankU2kU0 = kU2kU0berechnung(x,u2,u3,din)
u123 = [x(1)*exp(1i*x(2)/360*2*pi);u3;u2];
a = exp(1i*120/360*2*pi);
a2 = a^2;
T = [1 1 1; a2 a 1; a a2 1];
umg0 = T\u123;
meankU2kU0 = sqrt((abs((umg0(2)/umg0(1))*100)^2+((1-din)*abs((umg0(3)/umg0(1))*100))^2)/2);
end
Unfortunately, the fminsearch function stops after a few iterations. I think that this could be because the computer on which the model is running is too slow and then the Matlab function block in Simulink is triggered again before fminsearch is finished.
How can I adjust my model so that fminsearch really comes to a result?
Risposte (1)
Dimitri MANKOV
il 3 Lug 2023
0 voti
Hi Yannic,
I would suggest explicitly defining / checking the tolerances and stopping criteria of the "fminsearch" function in your code to make sure that it executes the correct number of times / until a good solution is found.
I doubt that the issue you're facing is due to the speed of your target machine: with Simulink Real-Time, if a process cannot not be completed before being triggered again, it would result in a CPU overload and the simulation would stop.
I hope this is helpful!
Dimitri
11 Commenti
Yannic Cullmann
il 3 Lug 2023
Yannic Cullmann
il 3 Lug 2023
Use "MaxIter" and "MaxFunEvals" out of the possible options:
"TolFun" and "TolX" might also be useful for your purpose.
Yannic Cullmann
il 3 Lug 2023
Yannic Cullmann
il 3 Lug 2023
Yannic Cullmann
il 3 Lug 2023
The time to solve was too long to execute it here.
If you have more luck with your MATLAB at home, you could hardcode the solution for Simulink.
I think the sqrt, the division by 2 and the factor 100 do not influence the minimum - so I deleted them.
syms x [2 1] real
syms u2 u3 din real
u123 = [x(1)*exp(1i*x(2)/360*2*pi);u3;u2];
a = exp(1i*120/360*2*pi);
a2 = a^2;
T = [1 1 1; a2 a 1; a a2 1];
umg0 = T\u123
meankU2kU0 = (umg0(2)/umg0(1))*conj(umg0(2)/umg0(1))+(1-din)^2*(umg0(3)/umg0(1))*conj(umg0(3)/umg0(1))
dx1 = diff(meankU2kU0,x(1))
dx2 = diff(meankU2kU0,x(2))
solve([dx1==0,dx2==0],x)
Yannic Cullmann
il 3 Lug 2023
As I said: If it works, you have explicit formulas for x(1) and x(2) that you can copy from the editor into a function file. Then it's just like evaluating an equation as
x(1) = a
x(2) = b
Yannic Cullmann
il 3 Lug 2023
Categorie
Scopri di più su Texas Instruments C2000 Processors in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!