Plots

Site: MSubbu Academy
Course: MATLAB for Chemical Engineers
Book: Plots
Printed by: Guest user
Date: Friday, 22 November 2024, 11:48 AM

1. Linear Plot

The plot command is used to create two dimensional plots. The simplest form of the command is:
>> plot(x,y)
where x is the array of independent variable, and y is the array of dependent variable.

MATLAB creates the plot automatically, scales the axes, marks the points and connects them with a straight line. It uses its default settings of line types, color, etc.
>> x = 1:2:50;
>> y = x.^2;
>> plot(x,y)
>>

2. Bar Chart

The following is the plot of marks vs. year for a subject in a question paper.
>> year=[2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022];
>> marks=[5,5,8,10,7,10,8,8,5,12,6,9,10];
>> bar(year,marks)
>> 

3. Example

The following is the plot of concentration vs. time data of a chemical reaction.
% ReactionOrder.m
% Concepts: plot, subplot, loglog, semilogx, semilogy
% Done by Subramanian M 
% on 6-June-2022

close all; clear; clc;

% define the row vector time in minutes
t = [1, 6, 11, 16, 21, 26, 50];
% define the row vector concentration (mol/L)
cA = [53.7, 31.3, 10.8, 7.8, 2.2, 1.65, 0.08];


subplot(2,2,1)
plot(t,cA,'o-')
grid on
xlabel('t (min)')
ylabel('C_A (mol/L)')
title('Linear Plot')

subplot(2,2,2)
loglog(t,cA,'o-')
grid on
xlabel('t (min)')
ylabel('C_A (mol/L)')
title('Log-Log Plot')


subplot(2,2,3)
semilogx(t,cA,'o-')
grid on
xlabel('t (min)')
ylabel('C_A (mol/L)')
title('SemiLogX Plot')

subplot(2,2,4)
semilogy(t,cA,'o-')
grid on
xlabel('t (min)')
ylabel('C_A (mol/L)')
title('SemiLogY Plot')
>> ReactionOrder



>>
Out of the above plots, the semilogY plot is giving a nice linear trend. This indicates \(\log(C_A)\) vs. \(t\) is linear. This is because of the data is that of first order reaction. \[ \begin{align*} -\frac{dC_A}{dt} &= kC_A \\ -\frac{dC_A}{C_A} &= kdt \\ \ln \frac{C_A}{C_{A0}} &= -kt \\ \ln(C_A) &= \ln(C_{A0}) - kt \\ \end{align*} \]