how to get sequence of values for 'u' in the for loop using the 'save control.mat u' syntax
1 view (last 30 days)
Show older comments
Sharath Talakallu
on 24 Apr 2019
Commented: Sharath Talakallu
on 24 Apr 2019
Mp = 0.4; % Kg
xp0 = 0.001485; % m
Kp = 242650; % N/m
Dp = 135.4; % N/m/s
Ap = 0.006; % m^2
alpha = 4.1054e-6; % m/s
V0 = 7.8e-5; % m^3
Km = 0.00106; % m^2
Cm = 42.74; % N
Aorifice = 2.0442e-5; % m^2
rho = 880; % kg/m^3
Cd = 0.7;
Patm = 1*10^5; % Pa
beta = 17000*10^5; % Pa
Ks = 0.00107; % m^2
Cs = 47.52; % N
Pc = 0; % Centrifugal pressure
delta_T = 0.000375; % Sample time
%% difining displacement velocity and pressure
steps=10;
X2=linspace(5,-1,steps);
U=linspace(0,2*10^5,20);
xfinal=[0.00058 0 187500]';
t=0.3;
lambda_2=1;
lambda_3=1;
lambda_4=1;
lambda_5=1;
for k=1:steps
for j=1:steps
X1= xfinal(1)-delta_T*X2(j);
X3=(1/(Ap-Km*tanh(X2(j)/alpha)))*(xfinal(2)-X2(j))*(Mp/delta_T)-Ap*(Pc-Patm)+Dp*X2(j)+Kp*(X1+xp0)+ (Cm+Km*Pc)*tanh((X2(j)/alpha));
a=[X1 X2(j) X3]';
xfinal=[X1,X2(j),X3]';
W=(xfinal(3)-X3)*((V0+Ap*X1)/(delta_T*beta))+Ap*X2(j);
u=sign(W)*(W/(Cd*Aorifice))^.2*(rho/2)+X3;
lambda=[lambda_3 0 0;0 lambda_4 0;0 0 lambda_5];
J_temp=lambda_2*(X2(j)-0)^.2+(a-xfinal)'*lambda*(a-xfinal);
save Control.mat u
end
end
0 Comments
Accepted Answer
Geoff Hayes
on 24 Apr 2019
Sharath - consider collecting all of the u values in a matrix and then saving it to file afterwards. For example,
% your code
u = zeros(steps,steps);
for k=1:steps
for j=1:steps
X1= xfinal(1)-delta_T*X2(j);
X3=(1/(Ap-Km*tanh(X2(j)/alpha)))*(xfinal(2)-X2(j))*(Mp/delta_T)-Ap*(Pc-Patm)+Dp*X2(j)+Kp*(X1+xp0)+ (Cm+Km*Pc)*tanh((X2(j)/alpha));
a=[X1 X2(j) X3]';
xfinal=[X1,X2(j),X3]';
W=(xfinal(3)-X3)*((V0+Ap*X1)/(delta_T*beta))+Ap*X2(j);
u(k,j)=sign(W)*(W/(Cd*Aorifice))^.2*(rho/2)+X3;
lambda=[lambda_3 0 0;0 lambda_4 0;0 0 lambda_5];
J_temp=lambda_2*(X2(j)-0)^.2+(a-xfinal)'*lambda*(a-xfinal);
end
end
save('Control.mat', 'u');
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!