Вы находитесь на странице: 1из 46

% Beacham

clc
clear
format bank
rad=0*0:0.10*pi:2.0*pi

degree=180/pi*rad

table=[rad',degree']

rad =

Columns 1 through 5

0 0.31 0.63 0.94 1.26

Columns 6 through 10

1.57 1.88 2.20 2.51 2.83

Columns 11 through 15

3.14 3.46 3.77 4.08 4.40

Columns 16 through 20

4.71 5.03 5.34 5.65 5.97

Column 21

6.28

degree =

Columns 1 through 5

0 18.00 36.00 54.00 72.00

Columns 6 through 10

90.00 108.00 126.00 144.00 162.00

Columns 11 through 15

180.00 198.00 216.00 234.00 252.00

Columns 16 through 20

270.00 288.00 306.00 324.00 342.00

1
Column 21

360.00

table =

0 0
0.31 18.00
0.63 36.00
0.94 54.00
1.26 72.00
1.57 90.00
1.88 108.00
2.20 126.00
2.51 144.00
2.83 162.00
3.14 180.00
3.46 198.00
3.77 216.00
4.08 234.00
4.40 252.00
4.71 270.00
5.03 288.00
5.34 306.00
5.65 324.00
5.97 342.00
6.28 360.00

Published with MATLAB® R2015b

2
Table of Contents
........................................................................................................................................ 1
3.4 Beacham ...................................................................................................................... 1
3.10 .................................................................................................................................. 2
3.11 .................................................................................................................................. 4
3.21 .................................................................................................................................. 5
3.22 .................................................................................................................................. 6
3.23 .................................................................................................................................. 7

clc
clear

3.4 Beacham
%k= ko*e^(-Q/(R*T))

%Q= 8000cal/mol
%R= 1.987cal/mol K
%ko= 1200amin^-1

Q=8000;
R= 1.987;
ko= 1200;
T= 100:50:500;

k= ko*exp(-Q./(R*T))
plot(T,k)
title(' 3.4')
xlabel('K dgrees')
ylabel('K values')

k =

Columns 1 through 5

0.00 0.00 0.00 0.00 0.00

Columns 6 through 9

0.01 0.05 0.16 0.38

1
3.10
Rad=0:0.1*pi:2.0*pi
sin(Rad)
cos(Rad)
tan(Rad)

Rad =

Columns 1 through 5

0 0.31 0.63 0.94 1.26

Columns 6 through 10

1.57 1.88 2.20 2.51 2.83

Columns 11 through 15

3.14 3.46 3.77 4.08 4.40

Columns 16 through 20

4.71 5.03 5.34 5.65 5.97

2
Column 21

6.28

ans =

Columns 1 through 5

0 0.31 0.59 0.81 0.95

Columns 6 through 10

1.00 0.95 0.81 0.59 0.31

Columns 11 through 15

0.00 -0.31 -0.59 -0.81 -0.95

Columns 16 through 20

-1.00 -0.95 -0.81 -0.59 -0.31

Column 21

-0.00

ans =

Columns 1 through 5

1.00 0.95 0.81 0.59 0.31

Columns 6 through 10

0.00 -0.31 -0.59 -0.81 -0.95

Columns 11 through 15

-1.00 -0.95 -0.81 -0.59 -0.31

Columns 16 through 20

-0.00 0.31 0.59 0.81 0.95

Column 21

1.00

ans =

Columns 1 through 5

3
0 0.32 0.73 1.38 3.08

Columns 6 through 10

16331239353195370.00 -3.08 -1.38 -0.73


-0.32

Columns 11 through 15

-0.00 0.32 0.73 1.38 3.08

Columns 16 through 20

5443746451065123.00 -3.08 -1.38 -0.73


-0.32

Column 21

-0.00

3.11
%x=A*cos(w*t)

%x= dispacement at time t


%A= maximum displacement
%w= angular frequency
%t= time

t= 0:10;
A= 4;
w= 0.6*pi;

x= A*cos(w.*t)
plot(t,x)
title('3.11')
xlabel('time')
ylabel('accelaration and displacement')

x =

Columns 1 through 5

4.00 -1.24 -3.24 3.24 1.24

Columns 6 through 10

-4.00 1.24 3.24 -3.24 -1.24

Column 11

4
4.00

3.21
clc
clear

tempature = randn(1,121)*2+70;
time=0:120;
plot(time,tempature)
Max_temp=max(tempature)
Max_time=max(time)
Min_temp=min(tempature)
Min_time=min(time)

Max_temp =

74.46

Max_time =

120.00

5
Min_temp =

65.01

Min_time =

3.22
clc
clear

Zl= complex(0,5);
Zc= complex(0,-15);
Zr= complex(5,0);
R=Zr;
Zt= Zl+Zc+R;
V= complex(10,0);
% Equation= V= I*Zt
% to get I we need to transform the equation to I= V/Zt
I= V/Zt

6
I =

0.40

3.23
C= 1e-6;
L= 200e-3;
R= 5;
f= 15e3;
w= 2*pi*f;
V= 10;

Zl= complex(0,5);
Zc= complex(0,-15);
Zr= complex(5,0);

Zc= 1/(w*C*1i)
Zl= w*L*1i

Zt= Zc+Zl+R

I= V/Zt

I_mag= abs(I)
ang = angle(I)

%%3.23b
Zt

%%3.23c
I= V/Zt

Zc =

0.00

Zl =

0.00

Zt =

5.00

I =

7
0.00

I_mag =

0.00

ang =

-1.57

Zt =

5.00

I =

0.00

Published with MATLAB® R2015b

8
% Problem 4.4 Sensor Data Beacham
% 9/16/13
clc
clear
load SENSOR.DAT
% Problem 4.4 a
%
time=1;
sensor_1=2;
sensor_2=3;
sensor_3=4;
sensor_4=5;
sensor_5=6;

[value_sensor_3,position_sensor_3]=max(SENSOR(:,sensor_3))
time_sensor_3=SENSOR(position_sensor_3,time)
[min_value_sensor_3,position_sensor_3]=min(SENSOR(:,sensor_3))
min_time_sensor_3=SENSOR(position_sensor_3,time)
%
[value_sensor_4,position_sensor_4]=max(SENSOR(:,sensor_4))
time_sensor_4=SENSOR(position_sensor_4,time)
[min_value_sensor_4,position_sensor_4]=min(SENSOR(:,sensor_4))
min_time_sensor_4=SENSOR(position_sensor_4,time)
%
[value_sensor_5,position_sensor_5]=max(SENSOR(:,sensor_5))
time_sensor_5=SENSOR(position_sensor_5,time)
[min_value_sensor_5,position_sensor_5]=min(SENSOR(:,sensor_5))
min_time_sensor_5=SENSOR(position_sensor_5,time)

% Problem 4.4c

mean_sensor_1= mean(SENSOR(:,sensor_1))
std_sensor_1= std(SENSOR(:,sensor_1))
%
mean_sensor_2= mean(SENSOR(:,sensor_2))
std_sensor_2= std(SENSOR(:,sensor_2))
%
mean_sensor_3= mean(SENSOR(:,sensor_3))
std_sensor_3= std(SENSOR(:,sensor_3))
%
mean_sensor_4= mean(SENSOR(:,sensor_4))
std_sensor_4= std(SENSOR(:,sensor_4))
%
mean_sensor_5= mean(SENSOR(:,sensor_5))
std_sensor_5= std(SENSOR(:,sensor_5))

% Problem 4.7 variable data

%probkem 4.7 homework


%determine the variables
%P= pressure

1
%w_p= water density
%m_p= mercury density
%h= height
%g= accelartion due to gravity
%hm_p= height of the mercury pressure
%hw_p= height of the water pressure
% problem 4.7 problem
P=0:100;
mercury_p=13.56;
water_p=1.00;
g=9.81;
hm_p=P/(mercury_p.*g);
hw_p=P/(water_p.*g);
% Was this supposed to be the answer?
Answer_1= hm_p.*hw_p
% Or should've I've used meshgrid?
[Height_Mercury, Height_Water]=meshgrid(hm_p,hw_p);
Mercury_Plus_Water= Height_Mercury.* Height_Water;

value_sensor_3 =

77.96

position_sensor_3 =

10.00

time_sensor_3 =

9.00

min_value_sensor_3 =

2.76

position_sensor_3 =

6.00

min_time_sensor_3 =

5.00

value_sensor_4 =

80.56

2
position_sensor_4 =

4.00

time_sensor_4 =

3.00

min_value_sensor_4 =

63.09

position_sensor_4 =

9.00

min_time_sensor_4 =

8.00

value_sensor_5 =

76.18

position_sensor_5 =

10.00

time_sensor_5 =

9.00

min_value_sensor_5 =

58.37

position_sensor_5 =

12.00

min_time_sensor_5 =

11.00

3
mean_sensor_1 =

69.73

std_sensor_1 =

4.55

mean_sensor_2 =

69.10

std_sensor_2 =

3.92

mean_sensor_3 =

65.37

std_sensor_3 =

15.36

mean_sensor_4 =

71.23

std_sensor_4 =

5.72

mean_sensor_5 =

68.26

std_sensor_5 =

5.24

Answer_1 =

4
Columns 1 through 5

0 0.00 0.00 0.01 0.01

Columns 6 through 10

0.02 0.03 0.04 0.05 0.06

Columns 11 through 15

0.08 0.09 0.11 0.13 0.15

Columns 16 through 20

0.17 0.20 0.22 0.25 0.28

Columns 21 through 25

0.31 0.34 0.37 0.41 0.44

Columns 26 through 30

0.48 0.52 0.56 0.60 0.64

Columns 31 through 35

0.69 0.74 0.78 0.83 0.89

Columns 36 through 40

0.94 0.99 1.05 1.11 1.17

Columns 41 through 45

1.23 1.29 1.35 1.42 1.48

Columns 46 through 50

1.55 1.62 1.69 1.77 1.84

Columns 51 through 55

1.92 1.99 2.07 2.15 2.23

Columns 56 through 60

2.32 2.40 2.49 2.58 2.67

Columns 61 through 65

2.76 2.85 2.95 3.04 3.14

Columns 66 through 70

5
3.24 3.34 3.44 3.54 3.65

Columns 71 through 75

3.75 3.86 3.97 4.08 4.20

Columns 76 through 80

4.31 4.43 4.54 4.66 4.78

Columns 81 through 85

4.90 5.03 5.15 5.28 5.41

Columns 86 through 90

5.54 5.67 5.80 5.93 6.07

Columns 91 through 95

6.21 6.35 6.49 6.63 6.77

Columns 96 through 100

6.92 7.06 7.21 7.36 7.51

Column 101

7.66

Published with MATLAB® R2015b

6
5.17 Beacham
clc
clear
% Equation used: P= Po*e^r*t
%P= Current balance
%Po= Initial balance
%r= growth constant (decimal)
%t= time invested (years)

Po= 1000;
r= 0.08;
t= 0:30;

P=Po*exp(r.*t);
table= [t;P];
disp('Build up of intrest')
disp(' Time, Amount')
fprintf('(%9.2f, %9.2f)\n',table)

% Grpahing
%a
subplot(2,2,1)
plot(t,P)
axis([0,50,1000,12000])
title('Build up of intrest - linear/linear')
xlabel('Time')
ylabel('Current Balance')
%b
subplot(2,2,2)
semilogx(t,P)
axis([0,150,1000,12000])
title('Build up of intrest - log/linear')
xlabel('Time')
ylabel('Current Balance')
%c
subplot(2,2,3)
semilogy(t,P)
axis([0,50,1000,12000])
title('Build up of intrest - linear/log')
xlabel('Time')
ylabel('Current Balance')
%d
subplot(2,2,4)
loglog(t,P)
axis([0,150,1000,12000])
title('Build up of intrest - log/log')
xlabel('Time')
ylabel('Current Balance')

Build up of intrest
Time, Amount

1
( 0.00, 1000.00)
( 1.00, 1083.29)
( 2.00, 1173.51)
( 3.00, 1271.25)
( 4.00, 1377.13)
( 5.00, 1491.82)
( 6.00, 1616.07)
( 7.00, 1750.67)
( 8.00, 1896.48)
( 9.00, 2054.43)
( 10.00, 2225.54)
( 11.00, 2410.90)
( 12.00, 2611.70)
( 13.00, 2829.22)
( 14.00, 3064.85)
( 15.00, 3320.12)
( 16.00, 3596.64)
( 17.00, 3896.19)
( 18.00, 4220.70)
( 19.00, 4572.23)
( 20.00, 4953.03)
( 21.00, 5365.56)
( 22.00, 5812.44)
( 23.00, 6296.54)
( 24.00, 6820.96)
( 25.00, 7389.06)
( 26.00, 8004.47)
( 27.00, 8671.14)
( 28.00, 9393.33)
( 29.00, 10175.67)
( 30.00, 11023.18)

2
Published with MATLAB® R2015b

3
clc
clear
y= 1:10;
x= [78.115, 46.07, 102.3];
moles= Grams_to_Moles(x,y)

moles =

78.1150 46.0700 102.3000


39.0575 23.0350 51.1500
26.0383 15.3567 34.1000
19.5287 11.5175 25.5750
15.6230 9.2140 20.4600
13.0192 7.6783 17.0500
11.1593 6.5814 14.6143
9.7644 5.7588 12.7875
8.6794 5.1189 11.3667
7.8115 4.6070 10.2300

Published with MATLAB® R2015b

1
% Problem 6.6b
clc
clear

%Define variables, and functions


%1 The two dimaters given, planet earth, and Mars.
diameter=[7926, 4218];
%2 To find the radians of the planets, you have to divide the dimater
by 2.
rad= diameter./2;
%3 The heights that we wish to find is an array.
hi_FEET= 0:1000:10000;
%4 The conversion factor from feet to miles.
Feet_Mile= 0.000189394;
%5 Note the heights need to be converted into miles to make it in the
%equation.

hi= hi_FEET.*Feet_Mile;
% The final answer, the distance traveled.
Answer= Distance(rad, hi);
disp(' Distance traveled')
disp(' Earth Mars')
disp(Answer)

Distance traveled
Earth Mars
0 0
38.7450 28.2648
54.7943 39.9734
67.1099 48.9583
77.4927 56.5334
86.6405 63.2077
94.9111 69.2421
102.5169 74.7917
109.5965 79.9575
116.2460 84.8097
122.5355 89.3993

Published with MATLAB® R2015b

1
Table of Contents
........................................................................................................................................ 1
7.17 a ................................................................................................................................ 1
7.17b ................................................................................................................................. 2
4.7 d ................................................................................................................................. 2

%%7.10
%Making a table that shows the relationship between angle in degrees,
angle
%in radians, and the sine of the angle (degree).

clc
clear
Angle_radians= 0.0*pi:0.1*pi:2.0*pi;
Sine_angle= sin(Angle_radians);
Angle_degree= Angle_radians*180/pi;
Table= [Angle_radians;Sine_angle;Angle_degree];
disp('degrees to radians cross reference')
disp('radiant, sin, degree')
fprintf('(%4.2f, %4.2f, %4.2f)\n',Table)

degrees to radians cross reference


radiant, sin, degree
(0.00, 0.00, 0.00)
(0.31, 0.31, 18.00)
(0.63, 0.59, 36.00)
(0.94, 0.81, 54.00)
(1.26, 0.95, 72.00)
(1.57, 1.00, 90.00)
(1.88, 0.95, 108.00)
(2.20, 0.81, 126.00)
(2.51, 0.59, 144.00)
(2.83, 0.31, 162.00)
(3.14, 0.00, 180.00)
(3.46, -0.31, 198.00)
(3.77, -0.59, 216.00)
(4.08, -0.81, 234.00)
(4.40, -0.95, 252.00)
(4.71, -1.00, 270.00)
(5.03, -0.95, 288.00)
(5.34, -0.81, 306.00)
(5.65, -0.59, 324.00)
(5.97, -0.31, 342.00)
(6.28, -0.00, 360.00)

7.17 a
clc
clear

1
Gas= 4;

7.17b
clc
clear
%Cost_of_car= Purchased_Cost+ Upkeep+ Gas
Purchased_Cost_1= 18720;
Purchased_Cost_2= 25350;
Gas= 4;
Upkeep= 0;
Mpg_1= 26;
Mpg_2= 33.5;
miles=0:25:375000;
Mi_1= Gas/ Mpg_1;
Mi_2=Gas/ Mpg_2;

Y1= miles.*Mi_1+ Purchased_Cost_1+Upkeep;


Y2= miles.*Mi_2+ Purchased_Cost_2+Upkeep;

plot(miles,Y1,miles,Y2)

%%4.7 c
[x,y]=ginput(1);
% reason why sprintf
Co_ordinate_string= sprintf('x co-ordinate: %f \n y co-ordinate:
%f',x,y);
gtext(Co_ordinate_string)
% X axis (Miles driven)= 1.9217e+05
% Y axis (Cost of Car)= 4.8377e+04

Error using ginput (line 75)


Interrupted by figure deletion

Error in Beacham_ch7_homework_First (line 40)


[x,y]=ginput(1);

4.7 d
fprintf(' When driven %f miles, that equals the cost of a car valuing
%f dollars',[x,y])

Published with MATLAB® R2015b

2
%%3.22
clc
clear

Zl= complex(0,5);
Zc= complex(0,-15);
Zr= complex(5,0);
R=Zr;
Zt= Zl+Zc+R;
V= complex(10,0);
% Equation= V= I*Zt
% to get I we need to transform the equation to I= V/Zt
I= V/Zt

I =

0.40

Published with MATLAB® R2015b

1
Table of Contents
........................................................................................................................................ 1
8.2a ................................................................................................................................... 2
8.2b .................................................................................................................................. 3
8.2c ................................................................................................................................... 3

% Beacham
% Homework problem 8.2 a b, and c
clc
clear

% Given variables, and constants.


% Time: a vector that goes from 0 to 100, with increments of 2(in
seconds).
% Height: distance traveled in the air (vertical, and in meters).
% Index_to_seconds: This is a constant, this converts Index values to
the
% corrosponding time value.
% one_matrix_for_dimensions: This is matrix is required to display the
% Maxium height of the rocket on the graph (uniform dimensions)

%Calculated variables.
% Positive_Heights_Index: this is a list of Index Values of all the
heights
% that are above 0 (Positive values)(still in the air, and not
underground).
% Last_pos_Index: The final Index Value produced that stayed in
accordance
%of the request.
% Maximum_Height: This will be the highest the rocket has traveled in
these
%conditions.
% time_index: The Index value that corresponds with the
Maximum_Height.
% Graphed_Max_Height: This is the version of the Max height that can
be
% disolayed onthe graph.
% Ground_level: This is the ground (x=0) because the rocket goes
% underground, that's why this should be displayed, for greater
% emphasis. (Note I could've used the_one_matrix_for_dimensions, but
% Matlab has a build in function to create matrixes completely out of
zeros

%Outputs
% Time_of_collision: This will give you the time when the rocket hit
the
%floor.
% Time_of_Max_Heightt: This will give us the time frames in which the

1
% rocket reached its top height.

% Variables required for all three problems.


time=0:2:100;
Height=2.13.*time.^2-0.0013.*time.^4+0.000034.*time.^4.751;

8.2a
We are finding at what time the rocket hit the floor,(it doesn't stop when it hits the ground though, it just
keeps going in a downwards direction).

% Constants.
% We know that one index value represents two seconds (look at
problem).
Index_to_seconds= 2;
% We also know that the index value is one less than the values shown
(zero
% has no index value, it starts at 1) so we have to make up for it by
% subtracing 1.

%Equation no.1
% We first have to find the points in which the height is still
positive.
Positive_Heights_Index=find(Height>0)
%Calculated variable
% This is the final positive position given from equation no.1.
Last_pos_Index= max(Positive_Heights_Index)
%Equation no.2
% We will be looking for the collision time, and therefore answer the
% question.
Time_of_collision= (Last_pos_Index-1)*Index_to_seconds;
% Addition.
% Better projection of answer.
disp('8.2 problem a')
disp('Time of impact in seconds')
disp(Time_of_collision)

Positive_Heights_Index =

Columns 1 through 5

2.00 3.00 4.00 5.00 6.00

Columns 6 through 10

7.00 8.00 9.00 10.00 11.00

Columns 11 through 15

12.00 13.00 14.00 15.00 16.00

Columns 16 through 20

2
17.00 18.00 19.00 20.00 21.00

Columns 21 through 25

22.00 23.00 24.00 25.00 26.00

Columns 26 through 30

27.00 28.00 29.00 30.00 31.00

Column 31

32.00

Last_pos_Index =

32.00

8.2 problem a
Time of impact in seconds
62.00

8.2b
We are looking for at what time the rocket reached its pick in height.

%Equation no.3
% We are looking for the highest distance the rocket went, and see the
% corresponding Index value for the rows (time).
[Maximum_Height, time_index]= max(Height);
%Equation no.4
% We will now convert the Index value to the time frame it's
representing.
Time_of_Max_Heightt= (time_index-1)*Index_to_seconds;
disp('8.2 problem b')
disp('Time when maximum height was reached, in seconds')
disp(Time_of_Max_Heightt)

8.2 problem b
Time when maximum height was reached, in seconds
40.00

8.2c
We want to make a graph that shows the relation of distance (height in meters) travelled in set times
(seconds)

% Additional iformation to add to the graph.

3
% This matrix is required to project the maximum height beam.
one_matrix_for_dimensions= ones(51);
% The actuall Max height beam.
Graphed_Max_Height= one_matrix_for_dimensions.*Maximum_Height;
% This is the ground, anything below means the rocket is going
underground.
% We use the zeros matrix to reach the required dimensions.
Ground_level= zeros(51);

%Actual graph.
Graph= plot(time,
Height,time,Graphed_Max_Height,'--',time,Ground_level,'k');

%Graphing info
title(' Rocket Launched, problem 8.2')
xlabel('time, in seconds')
ylabel('Height, in meters')
axis([0,100,-3000,2000])
grid on
legend('The rocket''s movements','Max height','Ground level')

Published with MATLAB® R2015b

4
Beacham 8.10
clc
clear

% Notation example: x= 5 y= 8, this is how the inputs should look


like.
disp(' In this experiment we will see comparisons between x, and y')
disp(' Only use nuubers to fill in the values. Thank You.')
X= input('Please plug in a value for X: ');
Y= input('Please plug in a value for Y: ');

if X>Y
disp(' The X value is greater than the Y vaalue')
elseif Y>X
disp(' Your X value is less than the Y canlue')
elseif X==Y
disp(' The X and Y values are the same')
else
disp(' Error please tru again')
end

In this experiment we will see comparisons between x, and y


Only use nuubers to fill in the values. Thank You.

Error using input


Cannot call INPUT from EVALC.

Error in Beacham_ch8_homework_Second_Problem_10 (line 9)


X= input('Please plug in a value for X: ');

Published with MATLAB® R2015b

1
BBeacham 8.16
clc
clear

Minimum_required_credits= menu('Please select a Engineering


Major:','Civil Engineer','Chemical Engineering','Computer
Engineer','Electrical Engineer','Mechanical Engineer');
switch Minimum_required_credits
case 1
disp('You will need at least 130 credits to graduate.')
case 2
disp('You will need at least 130 credits to graduate.')
case 3
disp('You will need at least 122 credits to graduate.')
case 4
disp('You will need at least 126.5 credits to graduate.')
case 5
disp('You will need at least 129 credits to graduate.')
end
disp(' Tnank you for using Matlab, have a nice day.')

You will need at least 122 credits to graduate.


Tnank you for using Matlab, have a nice day.

Published with MATLAB® R2015b

1
Beacham 9.3 Example.
clc
clear

% In this problem we will be making a table that will show the


relationship
% of radians and degrees.

% We will finding the coronation by using a loop, a While Loop to be


exact.
%degree: This is the side we are starting with.
%radians: We are going to convert our initial amount (degree) to get
find
%out the radians (degree/180*pi)
%Index: name chosen as our index value, main component of While Loop,
%logical component (Index>36)
%Table: The output.

% While Loop taking place.


Index= 1;
degree= 0:10:360;
radians= degree*(pi/180);
% It should've been 36, but remember that Wile Loops stop at the first
% unacceptable value, and because are max value is 360 it repeats, so
% that's why we did 36-1=35 to have all the numbers, without any
% repetitions.
while Index<=35
degree(Index)=Index*10;
radians(Index)= degree(Index)*pi/180;
Index= Index+1;
end

% We're going to re-format the radians value to have a better


% representation.(2pi set up)
radians= radians/pi;

% Making a visual representation of the comparison between degree and


% radians.

Table= [degree;radians]

disp(' Degree to Radians')


disp(' Degree Radians')
fprintf('%8.0f ° %8.2f Pi \n',Table)

Table =

Columns 1 through 5

10.00 20.00 30.00 40.00 50.00

1
0.06 0.11 0.17 0.22 0.28

Columns 6 through 10

60.00 70.00 80.00 90.00 100.00


0.33 0.39 0.44 0.50 0.56

Columns 11 through 15

110.00 120.00 130.00 140.00 150.00


0.61 0.67 0.72 0.78 0.83

Columns 16 through 20

160.00 170.00 180.00 190.00 200.00


0.89 0.94 1.00 1.06 1.11

Columns 21 through 25

210.00 220.00 230.00 240.00 250.00


1.17 1.22 1.28 1.33 1.39

Columns 26 through 30

260.00 270.00 280.00 290.00 300.00


1.44 1.50 1.56 1.61 1.67

Columns 31 through 35

310.00 320.00 330.00 340.00 350.00


1.72 1.78 1.83 1.89 1.94

Columns 36 through 37

350.00 360.00
1.94 2.00

Degree to Radians
Degree Radians
10 ° 0.06 Pi
20 ° 0.11 Pi
30 ° 0.17 Pi
40 ° 0.22 Pi
50 ° 0.28 Pi
60 ° 0.33 Pi
70 ° 0.39 Pi
80 ° 0.44 Pi
90 ° 0.50 Pi
100 ° 0.56 Pi
110 ° 0.61 Pi
120 ° 0.67 Pi
130 ° 0.72 Pi
140 ° 0.78 Pi
150 ° 0.83 Pi

2
160 ° 0.89 Pi
170 ° 0.94 Pi
180 ° 1.00 Pi
190 ° 1.06 Pi
200 ° 1.11 Pi
210 ° 1.17 Pi
220 ° 1.22 Pi
230 ° 1.28 Pi
240 ° 1.33 Pi
250 ° 1.39 Pi
260 ° 1.44 Pi
270 ° 1.50 Pi
280 ° 1.56 Pi
290 ° 1.61 Pi
300 ° 1.67 Pi
310 ° 1.72 Pi
320 ° 1.78 Pi
330 ° 1.83 Pi
340 ° 1.89 Pi
350 ° 1.94 Pi
350 ° 1.94 Pi
360 ° 2.00 Pi

Published with MATLAB® R2015b

3
% JaBeachamn Feyen
% Chapter 9 problem 18 a,b,d

% 9.18a
clc
clear
% In this part we will be squaring each indicial element of the random
X
% vector by using the While Loop which we'll use Comparison_Value as
the
% Main part used to work with the logical requirements. and we are
going to
% time how long Matlab will take to complete the loop.

% Our matrix with 100,000 random values, so we used rand function.


x= rand(1,100000);
% Our main component for the While Loop.

% Timer start.
tic
y= sqrt(x);
disp(' Matrix math')
toc

% 9.18b
clear x y
% Essentially we are going to do the same as 9.18a, but we are going
to
% use the For Loop to tackle this problem, (it's much easier to use
this
% method for this type of problem).

% Our matrix with 100,000 random values, so we used rand function.


x= rand(1,100000);
% Our answer will be known as Y, and for the way the For Loop works,
we
% much equal it to x
y=x;
%Start of timer.
tic
% For Loop going to work
for Index= 1:length(x);
y(Index)= sqrt(x(Index));

end
% End of timer.
disp(' For Loop square')
toc

1
% 9.18d

clear x y
% In this case we are going to follow the steops of 9.18b, and add C
in
% addition of squaring x.

% Our matrix with 100,000 random values, so we used rand function.


x= rand(1,100000);
% Our answer will be known as Y, and for the way the For Loop works,
we
% much equal it to x
y=x;
%new addition, from book.
C= (sin(0.3)+cos(pi/3))*factorial(5);
% Start of timer.
tic
% For loop ant work.
for Index= 1:length(x);
y(Index)= sqrt(x(Index))+C;

end
% End of timer.
disp(' For Loop plus C')
toc

%3.18d second

% Our matrix with 100,000 random values, so we used rand function.


x= rand(1,100000);
% Our answer will be known as Y, and for the way the For Loop works,
we
% much equal it to x
y=x;
% Rather than using c, we will add the actual value of C.
% Start of timer.
tic
% For loop ant work.
for Index= 1:length(x);
y(Index)= sqrt(x(Index))+(sin(0.3)+cos(pi/3))*factorial(5);

end
disp(' For Loop plus actual value of C')
toc

Matrix math
Elapsed time is 0.001486 seconds.
For Loop square
Elapsed time is 0.085082 seconds.
For Loop plus C
Elapsed time is 0.085998 seconds.
For Loop plus actual value of C

2
Elapsed time is 1.110865 seconds.

Published with MATLAB® R2015b

3
Beacham Chapter 10 Problem 16
clc
clear

% Given force in equation.


Force_lb= 35;
% Degree of the force
Alpha_angle= 55;
% the angle used for trig equations
Alpha_angle_theta= Alpha_angle/180*pi;
% creating matrix shooing relation
% Note that we are working with trigonometry, so all values are
radians.
% Note that because the force is a downwards force, it will have a
negative
% sign.
Vector= -1*Force_lb*[cosd(Alpha_angle);sind(Alpha_angle);0];
% Lenghts gvven of the brsckets
%Note: that tthe X axis is on the left from the origin, and therefore
%negative.
r_inches= [-10;5;0];
% Convert length into feet
R_feet= r_inches./12;
% Your Answer
Final_Answer= cross(Vector, R_feet);

% Display
fprintf('For the X axis co-ordinations\nthe moment of force for the
given bracket is %4.6f Lb per Feet \n',Final_Answer(1))
fprintf('For the Y axis co-ordinations\nthe moment of force for the
given bracket is %4.6f Lb per Feet \n',Final_Answer(2,1))
fprintf('For the Z axis co-ordinations\nthe moment of force for the
given bracket is %4.6f Lb per Feet \n',Final_Answer(3,1))

For the X axis co-ordinations


the moment of force for the given bracket is 0.000000 Lb per Feet
For the Y axis co-ordinations
the moment of force for the given bracket is 0.000000 Lb per Feet
For the Z axis co-ordinations
the moment of force for the given bracket is -32.256591 Lb per Feet

Published with MATLAB® R2015b

1
Beacham Chapter 10 problem 19
clc
clear

% Problem Statement.
% We are given lines of equations, but we are given an array of
unknown
% variables, so before we can tackle the problem, we must first figure
out the
% unknown variables.

% We can tackle this problem, and in fact we can use inverse method,
or
% left division.

% So we are going to use both methods to tackle this problem, and time
the
% process to see which method is more time efficient for Matlab
% First Problem

% 1st Matrix: Contains all the amounts of the unknown variables.


A= [3,4,2,-1,1,7,1;
2,-2,3,-4,5,2,8;
1,2,3,1,2,4,6;
5,10,4,3,9,-2,1;
3,2,-2,-4,-5,-6,7;
-2,9,1,3,-3,5,1;
1,-2,-8,4,2,4,5];
% 2nd Matrix: Contain the answers of all equations.
B=[42,32,12,-5,10,18,17];
% You have want to have the inner Dimensions of the Matrix to agree,
so
% you have to transpose one of the matrices. It's B. By transposing B
is
% now 7x1, while A is 7x7, so now the inner values matrices equal
B=B';

% Inverse Method
% % we can use tic toc set up to time, we will first use mathematics
to
%solve problem. We are using ^-1
tic
X1= (A^-1)*B
End_time_1= toc;

% Inverse Method
% we can use tic toc set up to time, and we can to inv()
%because the matrix is a square (2x2 3x3 4x4...)
tic

1
X2= inv(A)*B
End_time_2= toc;

% Left Division
% we will use tic toc set up to time, and now we will implement left
% division equation which is the preferred way, it's a much less error
% filled method than the inverse setup.
tic
X3= A\B
End_time_3= toc;

%re-formate the three values to have defined decimal count

X1=single(X1)
X2=single(X2)
X3=single(X3)

if X1==X2==X3

fprintf(' When we use power to the ^-1 to perform inverse method\n to


solve the problem Matlab takes %1.9f seconds to run the problem. \n',
End_time_1)
fprintf('When we use the inv function perform inverse method\n to
solve the nproblem Matlab takes %1.9f seconds to run the problem.
\n', End_time_2)
fprintf('When we use backward slash to perform left division\n to
solve the problem Matlab takes %1.9f seconds to run the problem. \n',
End_time_3)

fprintf('\n the value for x1 is %4.6f',All_unkonw_x_valuess(1))


fprintf('\n the value for x2 is %4.6f\t',All_unkonw_x_valuess(2,1))
fprintf('\n the value for x3 is %4.6f\t',All_unkonw_x_valuess(3,1))
fprintf('\n the value for x4 is %4.6f\t',All_unkonw_x_valuess(4,1))
fprintf('\n the value for x5 is %4.6f\t',All_unkonw_x_valuess(5,1))
fprintf('\n the value for x6 is %4.6f\t',All_unkonw_x_valuess(6,1))
fprintf('\n the value for x7 is %4.6f\t',All_unkonw_x_valuess(7,1))

else
disp('too bad, it isn''t equal out each other')
end

X1 =

-0.19
2.55
-3.28
-6.76
1.32
4.32
0.63

2
X2 =

-0.19
2.55
-3.28
-6.76
1.32
4.32
0.63

X3 =

-0.19
2.55
-3.28
-6.76
1.32
4.32
0.63

X1 =

-0.19
2.55
-3.28
-6.76
1.32
4.32
0.63

X2 =

-0.19
2.55
-3.28
-6.76
1.32
4.32
0.63

X3 =

-0.19
2.55
-3.28
-6.76
1.32
4.32
0.63

3
too bad, it isn't equal out each other

Published with MATLAB® R2015b

4
% Beacham
clc
clear

% Chapter 11 Practice problem 11.2

% Name string
name= 'Beacham'
% Searching for the computer's meaning of the letter g
Computer_translation= double('g')
% Converting 'matlab' to 'MATLAB' by using computer's languege
Matlab_computer_languege= double('matlab')
Displacemetn_of_Up_and_low= 32
MATLAB_computer_languege= Matlab_computer_languege-
Displacemetn_of_Up_and_low
MATLAB= char(MATLAB_computer_languege)

name =

Beacham

Computer_translation =

103

Matlab_computer_languege =

109 97 116 108 97 98

Displacemetn_of_Up_and_low =

32

MATLAB_computer_languege =

77 65 84 76 65 66

MATLAB =

MATLAB

Published with MATLAB® R2015b

1
Beacham Chapter 11 Special Homework
clc
clear

%Part 1: Using the above table

% in here we have different elements (all metals) and wit each metal
we are
% given its Atomic symbol, atomic number, atomic mass, its density and
its
% crystal structure.

%1) Build a padded character array of the metals called metal


metal= char('Aluminum', 'Copper', 'Iron', 'Molybdenum', 'Cobalt');
%2) Build a padded character array of the symbols called symbol
symbol= char('Al', 'Cu', 'Fe', 'Mo', 'Co');
%3) Build an integer array of the atomic numbers called A_num
A_num= [13, 29, 26, 42, 27]';
%4) Build a double array of the atomic weights called AW
AW= [26.98, 63.55, 55.85, 95.94, 58.93]';
%5) Build a double array of the densities called density
density= double([2.71, 8.94, 7.87, 10.22, 8.9])';
%6) Build a padded character array of the crystal structures called
structure
structure= char('FCC', 'FCC', 'BCC', 'BBC', 'HCP');

% Part 2: Using the arrays created in part 1

%7) Using a FOR loop we will create a structure called element_struct,


and
%we shall use the vectors from part one to create fields
% note that we are in need of (k,:). if we look at the metal, the
first
% metal is in the first row, however its charachers are in indivual
% collons, so that's why we use ':', it is a symbol that allows to
reach
% the max vale, without hardcoding.

for k= 1:length(A_num);
element_struct(k).metal=metal(k,:);
element_struct(k).symbol=symbol(k,:);
element_struct(k).A_num=A_num(k,:);
element_struct(k).AW= AW(k,:);
element_struct(k).density= density(k,:);
element_struct(k).structure= structure(k,:);

end

% Part Three: Find element with the highest density

1
% First we will extract the element with the highest densisty
[Density,vertical_location] = max([element_struct.density]);
% now we will use something like the index method to find the vertical
% placement, and link it with the corresponding metal element
Initial_highest_density_element =
element_struct(vertical_location).metal

% Part Four: Ask the user if he wishes to enter another element


%using a menu with two buttons; YES and NO

% In here we We’ll create a While Loop, and because of this we have


given
% the user the option to expand the system data base, and add any
more
% elements of his or her choosing. After choosing the element, the
user
% will be prompted to give some information of the element, it's
atomic
% mass, density, structure and such.

% simply showing that we are going to keep with the index value in
the
% previous created FOR Loop.
k=k;
%however because we don't want to overwrite
% any of the previous fields we must introduce a new lenght, 1
through 5
% is already taken, so the next value would be 6.
k= k+1;
a= k;
% Note that in Matlab, the first option is dubbed 1, and the second
option
% is 2, so you already have nubmers to work with for the loop
% yes= 1
% no= 2

% This question asks you if you wanna start the loop or not. THis
isn't
% part of the loop.
response = menu('Would you like to enter a value in the
system?','yes','no');
% The loop is tide in with the response of the question (1= yes)
while response==1

% Doing work
element_struct(k).metal= input('Please enter the name of the metal:
', 's');
element_struct(k).symbol=input('Please enter the atomic
symbol:', 's');

2
element_struct(k).A_num=input('Please put in the atomic number: ');
element_struct(k).AW=input('Please plug in its atomic mass: ');
element_struct(k).density=input('Please plug in its density: ');
element_struct(k).structure=input('Please plug in its
structure:', 's');
disp(element_struct(k))
% Seeing if information needs to be overwritten
incriment = menu('Is the plugged in data correct?','Yes','No');
switch incriment
case 1
incriment =1;
case 2
incriment = 0;
clc
end
k=k+incriment;

% Note that if you say yes you';; enter back into the loop, line 81
response = menu('Would you like to enter more elements?','yes','no');
end

% Part Five

% we could use Fprintf, or any other Matlab display function, but it


would
% only show us the final answer, and because we to see the evolution
step
%by step a Loop would do the job much better, and in this case we will
be
% using a FOR Loop

% Our Index value


%index= 1:length([element_struct.A_num])
% Our actual Loop
for index= 1:length([element_struct.A_num])
element_struct(index)

end
disp('end of program!')

Initial_highest_density_element =

Molybdenum

ans =

metal: 'Aluminum '


symbol: 'Al'
A_num: 13

3
AW: 26.9800
density: 2.7100
structure: 'FCC'

ans =

metal: 'Copper '


symbol: 'Cu'
A_num: 29
AW: 63.5500
density: 8.9400
structure: 'FCC'

ans =

metal: 'Iron '


symbol: 'Fe'
A_num: 26
AW: 55.8500
density: 7.8700
structure: 'BCC'

ans =

metal: 'Molybdenum'
symbol: 'Mo'
A_num: 42
AW: 95.9400
density: 10.2200
structure: 'BBC'

ans =

metal: 'Cobalt '


symbol: 'Co'
A_num: 27
AW: 58.9300
density: 8.9000
structure: 'HCP'

end of program!

Published with MATLAB® R2015b