not enough input arguments
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Halil Ibrahim
le 7 Jan 2024
Commenté : Sam Chak
le 8 Jan 2024
hi, I'm trying to write a code about cstr simulation and my loop cant continue due to this error, I'm sure it has what it needs for just first iteration but it does not calculate after the k1 part, can you help me please.
clear; clc;
Ts = 0.1;
%t = [1:0.1:1000];
Da1 = 3;
Da2 = 0.5;
Da3 = 1;
x1(1) = 0.5;
x2(1) = 0.5;
x3(1) = 1.5;
u = 0.45;
d2 = 1;
for n=1:1000
k1x1(n) = Ts*f1_func(x1(n),x2(n),Da1,Da2)
k1x2(n) = Ts*f2_func(x1(n),x2(n),Da1,Da2,Da3,d2,u)
k1x3(n) = Ts*f3_func(x2(n),x3(n),Da3,d2)
k2x1(n) = Ts*f1_func(x1(n)+k1x1(n)/2,x2(n)+k1x2(n)/2,u);
k2x2(n) = Ts*f2_func(x1(n)+k1x1(n)/2,x2(n)+k1x2(n)/2,u);
k2x3(n) = Ts*f3_func(x1(n)+k1x1(n)/2,x2(n)+k1x2(n)/2,x3(n)+k1x3(n)/2);
k3x1(n) = Ts*f1_func(x1(n)+k2x1(n)/2,x2(n)+k2x2(n)/2,u);
k3x2(n) = Ts*f2_func(x1(n)+k2x1(n)/2,x2(n)+k2x2(n)/2,u);
%k3x3
k4x1(n) = Ts*f1_func(x1(n)+k3x1(n),x2(n)+k3x2(n),u);
k4x2(n) = Ts*f2_func(x1(n)+k3x1(n),x2(n)+k3x2(n),u);
%k4x3
x1(n+1) = x1(n)+1/6*(k1x1(n)+2*k2x1(n)+2*k3x1(n)+k4x1(n));
x2(n+1) = x2(n)+1/6*(k1x2(n)+2*k2x2(n)+2*k3x2(n)+k4x2(n));
%x3
end
0 commentaires
Réponse acceptée
Walter Roberson
le 7 Jan 2024
You declare f1_func as expecting f1_func(x1,x2,Da1,Da2) but starting from
k2x1(n) = Ts*f1_func(x1(n)+k1x1(n)/2,x2(n)+k1x2(n)/2,u);
you only pass in three parameters.
Also
k1x2(n) = Ts*f2_func(x1(n),x2(n),Da1,Da2,Da3,d2,u)
you are passing in 7 parameters there, but
k2x2(n) = Ts*f2_func(x1(n)+k1x1(n)/2,x2(n)+k1x2(n)/2,u);
you are passing in 3 parameters there.
9 commentaires
Sam Chak
le 8 Jan 2024
I understand that the simulation code for the Adaptive PID controller is not completely fixed. However, I am not familiar with the RK4 version you coded. Now that the issue of passing extra parameters mentioned in your initial question has been resolved, it might be helpful to create a new question specifically addressing the "Index exceeds..." issue.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!