Sunday, August 06, 2006

Polyfitting in MATLAB

clc,clear
disp('Your Name')
t=[1,2,3,4,5,6];
y=[42,83,102,124,129,120];
coef=polyfit(t,y,2);
a1=coef(1);
a2=coef(2);
a3=coef(3);
disp('The values of g and vo are...')
g=-2*a1
vo=a2
yf=polyval(coef,t);
disp(' time y fitting y')
disp(' ')
disp([t',y',yf'])
plot(t,y,'o',t,yf)

Saturday, August 05, 2006

Rocket Trajectory for MATLAB 5.3

%Problem #2 Chapter #3 page 121 rocket trajectory

clc,clear

disp('Your Name')
disp('-')
disp('-')

t = 0:2:100;

for n = 1:51;
time = t(n);

h(n) = 60 + (2.13 * (time^2)) - (.0013 * (time^4)) + (.000034 * (time^4.751));
if h(n) >= 0 | h(n) <=0 [d, dtime] = max(h); [i, impact] = min(h); end
end
end
disp('This is the time in seconds after which the rocket starts to fall.')
t(dtime)
t(impact);
n = 1:51;
time = t(n);
[h(n)',time'];

for n = 1:51;
time = t(n);

h(n) = 60 + (2.13 * (time^2)) - (.0013 * (time^4)) + (.000034 * (time^4.751));
if h(n) <=0 disp('This is the time in seconds when the rocket has hit the ground.')
time
break
end
end

Saturday, July 22, 2006

More Practice

%Analytical theory
R1=1;
R2=2;
V1=12
Rth=R1+R2;
Ith=V1./Rth;
Vn1=Ith.*R1;
Vn2=Ith.*R2
V1=0:0.5:10
Ith=V1./Rth;
Vn1=Ith.*R1;
Vn2=Ith.*R2;
disp('Source volt Node Volt.')
Theory=[V1', Vn2']


subplot(2,2,1),plot(dcsweewb,Theory,'*'),title('Source vs. Node')
xlabel('Node voltage'),ylabel('Source voltage')
subplot(2,2,2),plot(pasweewb,'*'),title('Parameter Sweep')
xlabel('Resistance in ohms'),ylabel('Current in amps')
subplot(2,2,3),plot(transweb),title('Transient')
xlabel('Time in seconds'),ylabel('Node voltage')
subplot(2,2,4),plot(project1),title('Labview')
xlabel(''),ylabel('')

»
V1 =

12


Vn2 =

8


V1 =

Columns 1 through 7

0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000

Columns 8 through 14

3.5000 4.0000 4.5000 5.0000 5.5000 6.0000 6.5000

Columns 15 through 21

7.0000 7.5000 8.0000 8.5000 9.0000 9.5000 10.0000

Tuesday, July 11, 2006

MATLAB 5.3: Two Age Programs

clc %For a SIMPLE solution
clear
age=input('Enter your age :')
if age > 65
disp('senior')
elseif age > 20
disp('adult')
elseif age > 13
disp('teen')
elseif age > 0
disp('child')
elseif age < style="color: rgb(204, 0, 0);">'unborn')
end



clc %For a RANGE solution
clear
age=input('Enter your age :')
if age < style="color: rgb(204, 0, 0);">'unborn')
elseif 0<=age & age <=12 disp('child')
elseif 13<=age & age <=19 disp('teen')
elseif 20<=age & age <=65 disp('adult')
else
disp('senior')
end

The homework solution was the second one but I came up with the first and it was accepted as the right answer.

Thursday, July 06, 2006

MATLAB 5.3: Data Files

This homework will ask a user to enter 10 lottery numbers in two panels and then display those numbers in a table also a MS-WORD file will be brought in and display along with all variables used. The first will be saved as an ASCII/.dat file.


%saving and loading files by Your Name Here


clc
lotto1=input('Enter 5 numbers for the first lottery ticket panel');
lotto2=input('Enter 5 different numbers for the second lottery ticket panel');
disp('pick 1 pick 2')
table=[lotto1',lotto2'];
disp(table)
save yournamehere51.dat table /ascii
load YNHword.txt
disp('This is a MS Word file created earlier.')
disp(YNHword)
who
clear

Enter 5 numbers for the first lottery ticket panel[1,2,3,4,5]
Enter 5 different numbers for the second lottery ticket panel[6,7,8,9,99]
pick 1 pick 2
1 6
2 7
3 8
4 9
5 99

This is a MS Word file created earlier.
4 6 7
12 23 76


Your variables are:

YNHword lotto1 lotto2 table

Monday, July 03, 2006

MATLAB 5.3: Plotting

We were given three variables x, y1 and y2 and are asked to make two graphs and show procedures and results.

%two graphs are to be plotted along with rows and columns
clc
disp('Your name here')
x=0:10;
y1=0:10:100;
y2=[0,1,4,9,16,25,36,49,64,81,100];
disp(y1);
disp([y1]');
firstcomp=y2(6);
disp(firstcomp)
subplot(2,1,1),plot(x,y1);
title('Homework #? Graph');
xlabel('X Values''Y1 Values');
subplot(2,1,2),plot(x,y1,x,y2,'o');
title('Homework #? Graph');
xlabel('X Values'),ylabel('Y2 Values')
Your name here
0 10 20 30 40 50 60 70 80 90 100

0
10
20
30
40
50
60
70
80
90
100

25

Equilibrium Particles in Space

Objective: To determine the tension of cables both theoretically and experimentally. We will hang three cables at different locations on the ceiling of the force table. We will then tie about a 6kg mass to the end of the cables and measure the length of the cables. We will then calculate the tension using this information. Afterwards we will find the actual force using the spring scales at the top of the cable. The two answers will be compared and the percent error calculated. An explanation must be given for any percent difference.


Equipment Needed:
- 3 Cables -3 Hooks
- Load -Meter stick
- 3 Scales -Force table

Experimental Procedure: We get access to a force table and make sure it is up to working conditions. We then screw 3 hooks at 3 separate locations on the ceiling in the forces table, we then tighten them with nuts and washers. Then a spring scale is attached to each hook. Next cut a piece of string and tie one end to a hook. Do the preceding 2 more times for each hook and scale. Next tie all three strings together and place a 6.05kg mass on the point the strings meet. Then find a point on the ceiling that is perpendicular to the point where all the strings meet. This will be your zero point origin on the x, y, and z axes. Also find the distance from the origin on the ceiling to all three hooks along the x, y, and z axes. Then measure the distance of the string make sure to include the spring scale. Record all the measurements.


Theory: Equilibrium of particles in space is the theory that when the particle O is in equilibrium the sum of all forces is zero.
Fx = 0 Fy = 0Fz = 0


Results: In centimeters and kilograms and Newton.
A (-49, 73.5, 4.5) AO=87.5cm TOA = 24.5N
B (-10, 73.5 -45.5) BO=87cm TOB =14.7N
C (40, 73.5, 19) CO=86.5cm TOC =33.3N O (0, 0, 0) W=6.05kg
Theoretical Calculations: Only using x, y, and z position not the cable lengths or
tension found in experiment.

I. W= -6.05kg (9.8m/s2) = -59.35N

II. = A-O = (-49cm) î + (73.5cm) ĵ+ (4.5cm) k
____________________
OA=√ (-49)2+ (73.5)2+ (4.5) 2 = 88.45cm

λ OA = = -.55 î +.83 ĵ +.05 k
88.45

TOA λOA = -.55 TOA î +.83TOA ĵ +.05TOA k

III.  =B-O = (-10cm) î + (73.5cm) ĵ + (-45.5cm) k
______________________
OB=√ (-10) 2 + (73.5) 2 + (-45.5) 2 = 87.02cm

λ OB = = -.11 î +.84 ĵ -.52 k
87.02

TOB λOB = -.11 TOB î +.84TOB ĵ +.52TOB k

IV.OC = C-O = (40cm) î + (73.5cm) ĵ + (19cm) k
__________________
OC=√ (40) 2+ (73.5) 2+ (19) 2 =85.81cm

λ OC = OC= -.47 î +.86 ĵ +.22 k
85.81
TOC λOC = -.47 TOC î +.86TOC ĵ +.22TOC k

V. ∑Fx = 0
-.55 TOA î -.11 TOB î -.47 TOC î = 0
∑Fy = 0
83TOA ĵ +.84TOB ĵ +.86TOC ĵ – 59.35N = 0
∑Fz = 0
.05TOA k+.52TOB k+.22TOC k = 0


VI. Solve for the three unknowns with the three equations with these results:

TOA = 22.6N TOB = 15.4N TOC = 31.3N





Percent Error: E = theoretical value (estimated)
A = measured value (actual)
| E – A | × 100
A
Since I only used the position in space to calculate the cables tension and length I will have to find the percent error for OA, OB, OC, TOA, TOB and TOC.

OAE = 88.45 OBE = 87.02 OCE = 85.81
OAA = 87.50 OBA = 87.00 OCA = 86.50
Percent error = 1.09% = 0.02% = 0.80%

TOA E = 22.6N TOB E = 15.4N TOC E = 31.3N
TOA A = 24.5N TOB A = 14.7N TOC A = 33.3N
Percent error = 7.76% = 4.76% = 6.01%


Conclusion: The most likely reason for the error in the cable lengths is imprecise measurements by the people who did the measurements. When the meter stick was placed and the line plotted a small missed reading was put down. This gave the small percent errors for the lengths. This lead to a larger error when the figures were used in the more complicated tension formulas. The percent errors in tension then became much more magnified.

Repeat the experiment with out OB:
Given: A (-48, 74.5, -5.8) W = 6.05kg
C (41.5, 74.5, 6) TOA = 32.34N TOB = 35.28N


Theoretical Calculations: Only using x, y, and z position not the cable lengths or
tension found in experiment.


1. = A-O = (-48cm) î + (74.5cm) ĵ+ (-5.8cm) k
____________________
OA=√ (-48)2+ (74.5)2+ (-5.8) 2 = 88.81cm

λ OA = = -.54 î +.84 ĵ -.07 k
88.81

TOA λOA = -.54 TOA î +.84TOA ĵ +.07TOA k





2. OC =C-O = (-41.5cm) î + (74.5cm) ĵ + (6cm) k
______________________
OC=√ (-41.5) 2 + (74.5) 2 + (6) 2 = 85.49cm

λ OC = OC= -.49 î +.87 ĵ -.07 k
85.49

TOB λOB = -.49 TOB î +.87TOB ĵ +.07TOB k

3. ∑Fx = 0
-.54 TOA î-.49 TOB î = 0
∑Fy = 0
.84TOA ĵ+.87TOB ĵ -59.35N= 0
∑Fz = 0
.07TOA k+.07TOB k = 0

4. Solve for the two unknowns with the three equations with these results:

TOA = 32.99N TOB = 36.36N

5. Percent Error: E = theoretical value (estimated)
A = measured value (actual)
| E – A | × 100
A

OAE = 88.81 OCE = 85.49
OAA = 87.50 OCA = 86.50
Percent error = 1.50% =1.16%

TOA E = 32.99N TOC E = 36.36N
TOA A = 32.34N TOC A = 35.28N
Percent error = 2.01% =3.06 %

Conclusion: The tension on the cables increased as expected with the removal of cable OB. The percent error was closer to the actual measurements mostly because there were fewer things to plot.

Engineering School Homework

This is going to a place where I can store my old engineering work from college.

It includes MATLAB programs, Microsoft Excel, AutoCAD, Electronics Workbench and any others I use but now forgot.

It is a shame that blogger doesn't have catagories but I'll just use the search tool.

As for me well I don't matter just the fact that I'm trying to pass my classes and may need some input.