dsolve for multiple plots on a single figure
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2021-6-1
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)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
回答(1 个)
KALYAN ACHARJYA
2021-6-1
编辑:KALYAN ACHARJYA
2021-6-1
- 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!