sigmoid pid equation in matlab
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hai everyone , how do i write this sigmoid pid equation into matlab
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1012050/image.jpeg)
Réponse acceptée
Sam Chak
le 28 Mai 2022
Modifié(e) : Sam Chak
le 29 Mai 2022
Hi Shah
I'm curious to to see how your designed Kp looks like. What is the pid equation?
Edit: Kp is a nonlinear proportional gain shaped by the sigmoid curve that is bounded by
and
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1014755/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1014760/image.png)
% parameters
x = linspace(-6, 6, 1001);
Khigh = 5; % upper bound
Klow = 3; % lower bound
alpha = 1;
% construction of sigmoid
h = 1 + exp(-alpha*x);
g = Khigh - Klow;
f = g./h;
Kp = Klow + abs(f);
% plotting the nonlinear gain Kp
plot(x, Kp, 'linewidth', 1.5)
grid on
xlabel('error')
ylabel('Kp')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1014765/image.png)
5 commentaires
Sam Chak
le 29 Mai 2022
Modifié(e) : Sam Chak
le 29 Mai 2022
Hi @Shaz Shah
You did not comment about the suggested sigmoid in my previous post (edited to add an image of the plot). Anyhow, using the same parameters,
x = linspace(-6, 6, 1001);
Khigh = 5; % upper bound
Klow = 3; % lower bound
alpha = 1;
I have fixed your code
Kp = Klow - (abs(Khigh - Klow)./(1 + exp(-alpha*x)));
and plotted it
plot(x, Kp, 'linewidth', 1.5)
grid on
xlabel('error')
ylabel('Kp')
but I don't see any straight line. Sigmoid should look like an 'S'-shaped curve. Furthermore, the upper and lower bounds are definitely incorrect. You are advised to sketch the 'S'-curve with the upper and lower bounds. Only then, I can give a proper advice on getting the desired Sigmoid curve.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1014775/image.png)
Edit #1: I have made a minor modification. I think that your sigmoidal equation should look like this:
Kp = Khigh - (abs(Khigh - Klow)./(1 + exp(-alpha*x)));
Perhaps you mean this one:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1014780/image.png)
Edit #2: I guess you want to enter the 'AbsTol' as
1e-5
without the space between '1' and 'e'.
Query:
Is there a reason for you to select the Logistic function as a sigmoid curve? Better performance?
By the way, technically, this should work already
Kp = Khigh - (Khigh - Klow)./(1 + exp(-alpha*x));
where abs(X) is unnecessary.
Plus de réponses (1)
Mohd Ashraf
le 30 Nov 2022
Modifié(e) : Mohd Ashraf
le 30 Nov 2022
Hi Shah,
You may refer to this link:
https://drive.google.com/uc?export=download&id=1Ut-zX3cTKn3r_kepRDe7_A5WPlsW3qjs
for the detail of the sigmoid PID code.
0 commentaires
Voir également
Catégories
En savoir plus sur PID Controller Tuning dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!