You are on page 1of 1

MATLAB Command Window Page 1

>> % Constants
rho = 1000; % Density of the fluid (kg/m^3)
gravity = 9.81; % Acceleration due to gravity (m/s^2)

% Define the radius and center coordinates of each semi-circle


r1 = 2;
r2 = 4;
r3 = 1;

x1 = 2;
x2 = 8;
x3 = 13;

% Create a range of x values for each section


x_values1 = linspace(x1 - r1, x1 + r1, 500);
x_values2 = linspace(x2 - r2, x2 + r2, 500);
x_values3 = linspace(x3 - r3, x3 + r3, 500);

% Calculate y values for each section


y1 = sqrt(4 - (x_values1 - x1).^2);
y2 = sqrt(16 - (x_values2 - x2).^2);
y3 = sqrt(1 - (x_values3 - x3).^2);

% Calculate height as 50m minus the positive y values


height1 = 50 - y1;
height2 = 50 - y2;
height3 = 50 - y3;

% Calculate pressure for each section


pressure1 = rho * height1 * gravity;
pressure2 = rho * height2 * gravity;
pressure3 = rho * height3 * gravity;

% Create the figure and plot the pressure graph


figure;
plot(x_values1, pressure1, 'b', 'LineWidth', 2);
hold on;
plot(x_values2, pressure2, 'g', 'LineWidth', 2);
plot(x_values3, pressure3, 'r', 'LineWidth', 2);

% Customize the plot


title('Analog Pressure Graph along Semi-Circles' );
xlabel('x');
ylabel('Pressure (Pa)');
legend('Section 1', 'Section 2', 'Section 3');
grid on;

% Adjust the axis limits as needed


axis([0 15 0 max([pressure1, pressure2, pressure3])]);
>>

You might also like