Height vs Time Plot with Variable

Hi,
I have a Height vs Time plot for a tank which has 1 inlet and 2 outlets. I want to plot Height v Time with multiple lines with varying alpha values. I have created the code to plot the line for 1 alpha value but am unsure how to add multiple lines to show different values. The alpha values will be 0.01:0.01:0.2.
Any help will be much appreciated.
function dhdt = G_20_tankf1(t,h)
% G_20_tankf1: Tank level model
%Derivative function solution for Method 1
% Tank model parameters and chonstants
A = 8.0; %M^2
CV1 = 2; %(m^3/min)/(kPa^0.5)
P0 = 100; %kPa
P1 = P1function(t); %kPa
P3 = 100; %kPa
rho = 1000; %kg/m^3
g = 9.81; %m/s^2
alpha = 0.01;
% Algebraic equations for F1, F2, P2 and CV2 have been substituted
% into the differential equation for dh/dt to create a pure ODE system:
dhdt = 1/A*(CV1*sqrt(P1-P0-rho*g*h/1000) - 3*h*sqrt(P0+rho*g*h/1000-P3) - alpha*g*h);
% G_20_tanksim1: Method 1
%Extra Parameters
tf = 72; %h
h0 = 2 ; %m
% Solve the DAE
opts = odeset('RelTol',1e-5);
[t,h] = ode45(@G_20_tankf1,[0 tf],h0,opts);
% plot the graph
plot(t,h)
title('G20tanksim1')
xlabel('Time (h)')
ylabel('Level (m)')
grid on

 Accepted Answer

madhan ravi
madhan ravi on 2 Dec 2018
Edited: madhan ravi on 2 Dec 2018
% G_20_tanksim1: Method 1
%Extra Parameters
tf = 72; %h
h0 = 2 ; %m
% Solve the DAE
opts = odeset('RelTol',1e-5);
for alpha= 0.01:0.01:0.2
[t,h] = ode45(@(t,h)G_20_tankf1(t,h,alpha),[0 tf],h0,opts); %function call
figure
plot(h,t) % height vs time
% plot the graph
title('G20tanksim1')
xlabel('Time (h)')
ylabel('Level (m)')
grid on
end
function dhdt = G_20_tankf1(t,h,alpha) %function definition
% G_20_tankf1: Tank level model
%Derivative function solution for Method 1
% Tank model parameters and chonstants
A = 8.0; %M^2
CV1 = 2; %(m^3/min)/(kPa^0.5)
P0 = 100; %kPa
P1 = P1function(t); %kPa
P3 = 100; %kPa
rho = 1000; %kg/m^3
g = 9.81; %m/s^2
% Algebraic equations for F1, F2, P2 and CV2 have been substituted
% into the differential equation for dh/dt to create a pure ODE system:
dhdt = 1/A*(CV1*sqrt(P1-P0-rho*g*h/1000) - 3*h*sqrt(P0+rho*g*h/1000-P3) - alpha*g*h);
end

6 Comments

Hi Madhan,
Thankyou for your reply!
Your answer has worked thanks, but it displays each different alpha value on a seperate graph. Is there a way to plot them all on the same graph with a key for example?
Thanks again for your quick response.
just remove the line figure and put hold on after plot command , if my answer helped make sure to accept the answer and give a vote :)
Have done now. Thanks again!
Hi Madhan,
I have 1 more question:
Do you know how to add an automated legend to show each alpha value with a title for the legend of 'Alpha'?
My current solution is to write the following but I imagine there is a simpler way.
Thanks again
legend ('0.01','0.03','0.05','0.07','0.09','0.11','0.13','0.15','0.17','0.19');
Yes it does exist but at the moment I am having trouble finding it , sorry .

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!