Plotting graph Velocity vs Drag Force for incremental changes in the coefficient of drag value
Aim: Plotting graph for Velocity vs Drag Force for incremental changes in the coefficient of drag value.
Formula Fd=(0.5)*rho*Cd*A*v^2
Fd=Drag Force, rho=Density of force, Cd=Coefficient of Drag, A=Frontal Area, v=Velocity of Cyclist
Program
% Program for calculating Drag Force against a cyclist
% Step 1
clear all
close all
clc
% Step 2
% Variables
% Density of air in kg/m^3
rho=1.2;
% Frontal Area in m^2
A=1.2;
% Velocity of cyclist in m/s which is changing from 1 to 10
v=[1:10];
%Coeffient of Drag in m/s which is changing from 0.1 to 1.8
Cd=[0.1:0.1:1.8];
% In this program, we will plot velocity on X-axis
% & corresponding Drag Force on Y axis
% We will plot many curves with increment value of Drag Coefficient
% Drag force applied on cyclist by air
% Step 3
for i=1:length(Cd)
% Step 4
% To get each curve in different color
color=[rand rand rand];
% Step 5
%Basic Formula to calculate Drag Force
Fd=0.5*rho*A*Cd(i)*(v.*v);
% Step 6
%For holding previous curve in for loop
hold on
% Step 7
%plotting the curve
%I am writing Cd(i) to get different thickness for each curve
plot(v,Fd,'linewidth',Cd(i),'color',color)
% Step 8
%Labelling axis
xlabel('Velocity (m/s^2)')
ylabel('Drag Force (N)')
%Step 9
%Title for plot
title('Drag Force against a cyclist');
%Step 11
grid on
end
Stepwise Explanation
Step 1 Explanation: For clearing command window & workspace, closing all plots.
Step 2 Explanation: Defining variables. I have considered various values of velocity & drag Coefficient by defining Arrays.
Step 3 Explanation: I have used for loop because I want to create various plot for incremental changes in the coefficient of drag value.
Step 4 Explanation: Defining color variable to get each graph in different colour. Step 5Explanation: Used formula for Drag Force.
Step 6 Explanation: Used hold on command to hold previous plot.
Step 7 Explanation: Plotting velocity on X axis & Drag Force on Y axis. Used Cd(i) to get increasing thickness of plot with increasing value of Cd.
Step 8 Explanation: Labelling velocity to X axis & Drag Force to Y axis.
Step 9 Explanation: to give title to plot.
Step 10 Explanation: I want to label each curve as per value of Drag Coefficient, hence I have used this new functions ‘sprintf’ & ‘legend’
Step 11 Explanation: To turn on grid.
Error & Solution: I want to show valve of Cd (Coefficient of Drag) for each curve but I am unable to do it. I have tried many methods. Finally, by discussing this issue with Skill Lync expert, I have decided to use legend command. For that I used sprint command & store valve of Cd(i) in cell array by using text{i}. Below you can see previous plot & revised plot.
Revised & Previous Plot