Computers in Engineering Tutorial 1 PDF
Computers in Engineering Tutorial 1 PDF
(1+sqrt(5))/2
ans =
1.6180
%The result is stored under the Workspace tab with the variable name 'ans'
GoldenRatio=(1+sqrt(5))/2
GoldenRatio =
1.6180
%Question 2
((2^3)+7)/((3^2)-sqrt(16))
ans =
%Question 3
x=0;
a=cos(x)
a=
Page | 1
1
b=sin(x)
b=
c=tan(x)
c=
x=pi/2
x=
1.5708
a=cos(x)
a=
6.1232e-17
b=sin(x)
b=
Page | 2
1
c=tan(x)
c=
1.6331e+16
x=pi/4;
a=cos(x)
a=
0.7071
b=sin(x)
b=
0.7071
c=tan(x)
c=
1.0000
x=pi/6;
Page | 3
a=cos(x)
a=
0.8660
b=sin(x)
b=
0.5000
c=tan(x)
c=
0.5774
x=pi;
a=cos(x)
a=
-1
b=sin(x)
b=
Page | 4
1.2246e-16
c=tan(x)
c=
-1.2246e-16
x=2*pi;
a=cos(x)
a=
b=sin(x)
b=
-2.4493e-16
c=tan(x)
c=
-2.4493e-16
Page | 5
ans =
x=
a=cos(x)
a=
b=sin(x)
b=
c=tan(x)
c=
1.0e+16 *
Page | 6
%Question 4
r=1:4;
area=pi*(r^2)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a
scalar. To
}
area=pi*(r.^2)
area =
a=0:2:10
a=
0 2 4 6 8 10
help linespace
--- <strong>linespace</strong> not found. Showing help for <strong>linspace</strong> instead. ---
Page | 7
<strong>linspace</strong>(X1, X2, N) generates N points between X1 and X2.
<a
href="matlab:matlab.internal.language.introspective.overloads.displayOverloads('linspace')">Other
functions named linspace</a>
linspace(0,10,2)
ans =
0 10
linspace(0,10,6)
ans =
0 2 4 6 8 10
b=linspace(0,10,6)
b=
Page | 8
0 2 4 6 8 10
c=a+b
c=
0 4 8 12 16 20
%Question #6
X=0:3:2pi
X=0:3:2pi
{Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters,
or other syntax
}
X = 0:3:2*pi
X=
0 3 6
X=0:3:(2*pi)
X=
0 3 6
Page | 9
Ya=cos(X)
Ya =
Yb=sin(X)
Yb =
0 0.1411 -0.2794
[Warning: MATLAB has disabled some advanced graphics rendering features by switching to software
OpenGL. For more
Page | 10
%Question 7
x=0:0.25:8;
y=(3*x)+2;
plot(x,y)
x=0:0.1:2;
y=exp(-x^2);
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a
scalar. To
}
y=exp(-x.^2);
plot(x,y)
Page | 11
x=0:pi/10:2*pi
x=
Columns 1 through 12
0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.1991 2.5133 2.8274 3.1416
3.4558
Columns 13 through 21
y=cos(x);
plot(x,y)
Page | 12
x=1:0.5:4;
y=(ln(exp(x)))^-1
}
help ln
ln not found.
Use the Help browser search field to <a href="matlab:docsearch ln">search the documentation</a>, or
type "<a href="matlab:help help">help help</a>" for help command options, such as help for methods.
look ln
}
logo ln
Page | 13
C:\Program Files\MATLAB\R2018b\toolbox\matlab\general\logo.m
}
where ln
}
iskeyword ln
ans =
which ln
y=(log(exp(x)))^-1;
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a
scalar. To
}
y=(log(exp(x))).^-1;
plot(x,y)
Page | 14
%Question #8
A=
1 2 3 4
11 12 13 14
21 22 23 24
size A
ans =
1 1
size(A)
Page | 15
ans =
3 4
VecA=A(3,:)
VecA =
21 22 23 24
VecB=A(:,2)
VecB =
12
22
Ele=A(3,4)
Ele =
24
A'
ans =
Page | 16
1 11 21
2 12 22
3 13 23
4 14 24
A[1 2; 34];
A[1 2; 34];
{Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise,
check for
mismatched delimiters.
}
A=[1 2; 3 4];
B=[2 2; 2 2];
%Question 9
A=[1 2; 3 4];
B=[2 2; 2 2];
A+B
ans =
3 4
5 6
A-B
ans =
Page | 17
-1 0
1 2
A*B
ans =
6 6
14 14
A.*B
ans =
2 4
6 8
A^2
ans =
7 10
15 22
A*A
ans =
7 10
Page | 18
15 22
A.^2
ans =
1 4
9 16
A^B
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a
scalar. To
}
A.^B
ans =
1 4
9 16
A=[1 2 3; 4 5 6];
size(A)
ans =
2 3
Page | 19
reshape(A,1,6)
ans =
1 4 2 5 3 6
Av=reshape(A,1,6)
Av =
1 4 2 5 3 6
min(Av)
ans =
max(Av)
ans =
Page | 20