dsolve for multiple plots on a single figure
    7 ビュー (過去 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 で Equation Solving についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


