dsolve for multiple plots on a single figure
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have the following code that works for Kc = 1 and plots well enough. But I want to also plot Kc for 2, 3, 4 and 5 as well, and I don't know how to do this.
clear all; clc; % clear workspace and editor, respectively
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = 2; % cross-sectional area (m^2)
T = 0.1; % integral time constant (min)
Kc_1 = 1; % proportional gain (m^2/min)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms y(x) % symbolic variable with deviation in height of liquid, y, and time, x
dy = diff(y); % dy is the differential of the deviation in height of liquid, y
ODE = A * diff(y,x,2)+ Kc_1 * diff(y,x)+((Kc_1/T)*y) == 0; % second-order ODE for a PI controller
cond1 = y(0) == 0; % first condition
cond2 = dy(0) == 2; % second condition
conds = [cond1 cond2];
ySol(x) = dsolve(ODE,conds);
ySol = simplify(ySol);
fplot(ySol,'b')
legend('Kc = 1')
title('Proportional-Integral Control of Liquid Height in Tank')
xlabel('Time (min)')
xlim([0,25])
ylabel('Deviation Height (m)')
ylim([-0.6 0.8])
set (gca, 'fontsize', 20)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1 Kommentar
Rik
am 1 Jun. 2021
Backup of this question:
dsolve for multiple plots on a single figure
I have the following code that works for Kc = 1 and plots well enough. But I want to also plot Kc for 2, 3, 4 and 5 as well, and I don't know how to do this.
clear all; clc; % clear workspace and editor, respectively
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = 2; % cross-sectional area (m^2)
T = 0.1; % integral time constant (min)
Kc_1 = 1; % proportional gain (m^2/min)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms y(x) % symbolic variable with deviation in height of liquid, y, and time, x
dy = diff(y); % dy is the differential of the deviation in height of liquid, y
ODE = A * diff(y,x,2)+ Kc_1 * diff(y,x)+((Kc_1/T)*y) == 0; % second-order ODE for a PI controller
cond1 = y(0) == 0; % first condition
cond2 = dy(0) == 2; % second condition
conds = [cond1 cond2];
ySol(x) = dsolve(ODE,conds);
ySol = simplify(ySol);
fplot(ySol,'b')
legend('Kc = 1')
title('Proportional-Integral Control of Liquid Height in Tank')
xlabel('Time (min)')
xlim([0,25])
ylabel('Deviation Height (m)')
ylim([-0.6 0.8])
set (gca, 'fontsize', 20)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Antworten (1)
KALYAN ACHARJYA
am 1 Jun. 2021
Bearbeitet: KALYAN ACHARJYA
am 1 Jun. 2021
- Using Loop
A = 2; % cross-sectional area (m^2)
T = 0.1; % integral time constant (min)
Kc_1 = 1:5;
for i=1:length(Kc_1)
code
%replace Kc_1 with Kc_1(i)...........
legend(['Kc =',num2str(i)])
hold on
end
title('Proportional-Integral Control of Liquid Height in Tank')
xlabel('Time (min)')
xlim([0,25])
ylabel('Deviation Height (m)')
ylim([-0.6 0.8])
set (gca, 'fontsize', 20)
2. or Create an another function file & pass the Kc_1 as input argument.
3. or Create function handle & substitute Kc_1 value after solve.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Applications finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!