dsolve for multiple plots on a single figure

1 回表示 (過去 30 日間)
Tony Rankin
Tony Rankin 2021 年 6 月 1 日
コメント済み: Rik 2021 年 6 月 1 日
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
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
KALYAN ACHARJYA 2021 年 6 月 1 日
編集済み: KALYAN ACHARJYA 2021 年 6 月 1 日
  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.

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by