Solution Matlab
Solution Matlab
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
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Column 21
6.28
degree =
Columns 1 through 5
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
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
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
Columns 6 through 9
1
3.10
Rad=0:0.1*pi:2.0*pi
sin(Rad)
cos(Rad)
tan(Rad)
Rad =
Columns 1 through 5
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
2
Column 21
6.28
ans =
Columns 1 through 5
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Column 21
-0.00
ans =
Columns 1 through 5
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Column 21
1.00
ans =
Columns 1 through 5
3
0 0.32 0.73 1.38 3.08
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Column 21
-0.00
3.11
%x=A*cos(w*t)
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
Columns 6 through 10
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
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))
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
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Columns 21 through 25
Columns 26 through 30
Columns 31 through 35
Columns 36 through 40
Columns 41 through 45
Columns 46 through 50
Columns 51 through 55
Columns 56 through 60
Columns 61 through 65
Columns 66 through 70
5
3.24 3.34 3.44 3.54 3.65
Columns 71 through 75
Columns 76 through 80
Columns 81 through 85
Columns 86 through 90
Columns 91 through 95
Column 101
7.66
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 =
1
% Problem 6.6b
clc
clear
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
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)
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;
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
4.7 d
fprintf(' When driven %f miles, that equals the cost of a car valuing
%f dollars',[x,y])
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
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
%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.
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
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
2
17.00 18.00 19.00 20.00 21.00
Columns 21 through 25
Columns 26 through 30
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)
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')
4
Beacham 8.10
clc
clear
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
1
BBeacham 8.16
clc
clear
1
Beacham 9.3 Example.
clc
clear
Table= [degree;radians]
Table =
Columns 1 through 5
1
0.06 0.11 0.17 0.22 0.28
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Columns 21 through 25
Columns 26 through 30
Columns 31 through 35
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
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.
% 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).
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.
end
% End of timer.
disp(' For Loop plus C')
toc
%3.18d second
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.
3
Beacham Chapter 10 Problem 16
clc
clear
% 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))
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
% 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;
X1=single(X1)
X2=single(X2)
X3=single(X3)
if X1==X2==X3
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
4
% Beacham
clc
clear
% 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 =
Displacemetn_of_Up_and_low =
32
MATLAB_computer_languege =
77 65 84 76 65 66
MATLAB =
MATLAB
1
Beacham Chapter 11 Special Homework
clc
clear
% 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.
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
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
% 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
end
disp('end of program!')
Initial_highest_density_element =
Molybdenum
ans =
3
AW: 26.9800
density: 2.7100
structure: 'FCC'
ans =
ans =
ans =
metal: 'Molybdenum'
symbol: 'Mo'
A_num: 42
AW: 95.9400
density: 10.2200
structure: 'BBC'
ans =
end of program!