Computer Applications in Engineering Design: Introductory Lecture
Computer Applications in Engineering Design: Introductory Lecture
Computer Applications in Engineering Design: Introductory Lecture
Engineering Design
MATLAB
AutoCAD
Visio
Rational Rose
LabVIEW
PSPICE
Orcad
Introductory Lecture
Course Syllabus
MATLAB
Orcad
Visio
Pspice
AutoCAD
Rational Rose
LabVIEW
UML
Tools
Introduction to
Matlab
Click on the Matlab
icon/start menu
initialises the
Matlab
environment:
Variable
browser
Command
window
Command
history
Matlab Programming
Environment
Matlab (Matrix Laboratory)
is a dynamic, interpreted,
environment for
matrix/vector analysis
Variables are created at runtime, matrices are
dynamically re-sized,
User can build programs (in
.m files or at command
line) using a C/Java-like
syntax
Ideal environment for model
building, system
identification and control
(both discrete and
Variables
No need for types. i.e.,
int a;
double b;
float c;
All variables are created with double precision
unless specified and they are matrices.
Example:
>>x=5;
>>x1=2;
After these statements, the variables are 1x1
matrices with double precision
Basic Matlab
Example
a=[1,2,3,4,5];
b=[a;a;a]
Example
a=[1;2;3;4;5];
b=[a,a,a]
b=1 2 3 4 5
12345
12345
b= 1 1 1
222
333
444
555
Example (transpose)
a=[1;2;3;4;5];
b=a
b= 1 2 3 4 5
Input/Output Statements
Input Function
Keyboard Command
Menu Function
Pause Command
Formatting plots.
Plot title
1200
y axis
label
Legend
Theory
Experiment
1000
Text
Tick-mark
INTENSITY (lux)
800
Comparison between theory and experiment.
600
400
Data symbol
200
10
12
x axis
label
14
16
DISTANCE (cm)
18
20
22
24
Tick-mark label
plot(x,y)
where x is a vector (one dimensional array), and y is a vector.
Both vectors must have the same number of elements.
The plot command creates a single curve with the
the abscissa (horizontal axis) and the
(vertical axis).
x values on
and
coordinates of the
If the values of
7.5
10
6.5
5.5
plot(x,y,line specifiers)
plot(x,y,line specifiers)
Line
Style
Solid
dotted
dashed
dash-dot
Specifier
:
--.
Line
Color
Specifier
red
green
blue
Cyan
magenta
yellow
black
r
g
b
c
m
y
k
Marker Specifier
Type
plus sign
circle
asterisk
point
square
diamond
+
o
*
.
s
d
1988
1989
1990
1991
1992
1993
1994
Sales (M)
127
130
136
145
158
178
211
Line Specifiers:
dashed red line and
asterisk markers.
cos(6 x)
Consider: y 3.5
A script file for plotting the function is:
for 2 x 4
Once the plot command is executed, the Figure Window opens with
the following plot.
A PLOT OF A FUNCTION
y 3.5
0.5 x
cos(6 x)
for 2 x 4
x = [-2:0.3:4];
y = 3.5.^(-0.5*x).*cos(6*x);
plot(x,y)
= f(x)
fplot(function,limits)
The function is typed in as a string.
The limits is a vector with the domain of x, and optionally with limits
of the y axis:
[xmin,xmax]
or
[xmin,xmax,ymin,ymax]
y x 2 4 sin( 2 x) 1
A plot of:
>> fplot('x^2 + 4 * sin(2*x) - 1', [-3 3])
for 3 x 3
plot(x,y,u,v,t,h)
Plots three graphs in the same plot:
y versus x, v versus u,
and h versus t.
plot(x,y,-b,u,v,r,t,h,g:)
Vector ydd
with values of the second derivative.
2 x 4
plot(x,y,'-b',x,yd,'--r',x,ydd,':k')
-1
hold on
x = [-2:0.01:4];
y = 3*x.^3-26*x+10;
yd = 9*x.^2-26;
ydd = 18*x;
plot(x,y,'-b')
hold on
plot(x,yd,'--r')
plot(x,ydd,':k')
hold off
1200
Legend
Theory
Experiment
y axis
label
1000
Text
Tick-mark
INTENSITY (lux)
800
Comparison between theory and experiment.
600
400
Data symbol
200
10
12
x axis
label
14
16
18
DISTANCE (cm)
20
22
24
Tick-mark label
FORMATTING PLOTS
FORMATTING PLOTS
FORMATTING COMMANDS
title(string)
Adds the string as a title at the top of the plot.
xlabel(string)
Adds the string as a label to the x-axis.
ylabel(string)
Adds the string as a label to the y-axis.
FORMATTING COMMANDS
legend(string1,string2,string3)
Creates a legend using the strings to label various curves
(when several curves are in one plot). The location of the
legend is specified by the mouse.
text(x,y,string)
Places the string (text) on the plot at coordinate x,y relative to
the plot axes.
gtext(string)
Places the string (text) on the plot. When the command
executes the figure window pops and the text location is clicked
with the mouse.
Below is a script file of the formatted light intensity plot (2nd slide).
x=[10:0.1:22];
y=95000./x.^2;
xd=[10:2:22];
ylabel('INTENSITY (lux)')
legend('Theory','Experiment',0)
The plot that is obtained is shown again in the next slide.
Use Figure,
Axes, and
Current ObjectProperties in
the Edit menu
SUB-PLOTS
i=1:4;
v=4*i;
subplot(2,2,1);
plot(i,v);
x=[1 2 3 4];
y=[1 4 9 16]
subplot(2,2,2)
plot(x,y);
t=0:pi:2*pi;
subplot(2,2,3)
plot(t,sin(t));
20
20
15
15
10
10
-16
x 10
0
-2
-4
cos-x
x=0:0.02:4*pi;
y=cos(x);
area(x,y);
xlabel(x-axis);
ylabel(cos-x);
title(graph to plot y=cos(x)
using area function);
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
6
x-axis
10
12
Bar Function
bar(y)
bar(x,y)
bar(x,y,style option)
bar3(x,y,g)
30
25
y-label
20
x=[0 1 2 3 4 5 6];
y=[10 15 25 20 30 27 19];
bar(x,y,c);
xlabel(x-axis);
ylabel(y-label);
title(graph to show bar
function);
15
10
3
x-axis
Barh Function
6
5
4
y-label
x=[0 1 2 3 4 5 6];
y=[10 15 25 20 30 27 19];
barh(x,y,g);
xlabel(x-axis);
ylabel(y-label);
title(graph to show barh
function);
3
2
1
0
10
15
x-axis
20
25
30
Pie Function
pie chart showing concentration of different industry
pie(x)
pie(x,k)
pie(x,k,labels)
8%
20%
16%
industry=[4 8 20 2 7 10];
pie(industry);
title(pie chart showing
concentration of different
industry)
14%
4%
39%
industry=[4 8 20 2 7 10];
show=[0 0 0 1 0 1];
pie(industry,show);
title(pie chart showing concentration of different industry);
legend(cement,textile,software,chemical,telecom,Banking,3)
Pie Function
20%
16%
14%
cement
textile
software
chemical
telecom
Banking
39%
4%
Stairs Function
stairs plot to show function
y-label
x=-2:0.1:2;
3.5
y=x.*x;
3
stairs(x,y,'r');
2.5
grid on;
2
xlabel('x-axis');
ylabel('y-label');
1.5
title('stairs plot to show function')1
0.5
0
-2
-1.5
-1
-0.5
0
x-axis
0.5
1.5
Stem Function
x=[0 1 2 3 4 5 6]
y=[3 -1 -6 4 5 2 3]
stem(x,y);
-2
-4
-6
4
2
z-axis
t=-4:0.1:4;
x=t.^2;
y=4*t;
plot3(x,y,t);
grid on;
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
title('illustration of plot3
function)ction')
0
-2
-4
20
10
0
-10
y-axis
-20
10
x-axis
15
20