Sunteți pe pagina 1din 28

7/11/14

Homework #2

Renan Santos

Names of people you worked with:

Websites you used:

By writing or typing your name below you affirm that all of the work
contained herein is your own, and was not copied or copied and altered.
RENAN SANTOS

Lab time (eg tues 10am):


Note: Change the homework number and name at the top of the page by selecting
view->header and foot. Failure to change the name and to sign this page will result
in a 5% point penalty.

7/11/14

Homework #2

Renan Santos

Problem 1
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clear all
clc
% Creating Variables
ts1=linspace(0,1,100);
ts2=linspace(0,1,100);
%calculating array length
length(ts1)
length(ts2)
%Checking the first and last elements of ts1 and ts2
ts1(1)
ts2(1)
ts1(end)
ts2(end)
%calcuating the sum, the minimum value and the average number of ts1
sum(ts1)
min(ts1)
mean(ts1)
%Creating tsRev
tsRev=linspace(1,0,100);
%Checking the first and last elements of tsRev
tsRev(1)
tsRev(end)

Function File (if applicable)


Command Window Output (cut and paste output here)
ans =
100
ans =
100

7/11/14

Homework #2

ans =
0
ans =
0
ans =
1
ans =
1
ans =
50.0000
ans =
0
ans =
0.5000
ans =
1
ans =
0

Renan Santos

7/11/14

Homework #2

Renan Santos

Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

7/11/14

Homework #2

Renan Santos

Problem 2
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clear all
clc
% Creating Variables
ts1=linspace(0,1,100);
ts2=linspace(0,1,100);
%calculating array length
length(ts1)
length(ts2)
%Checking the first and last elements of ts1 and ts2
ts1(1)
ts2(1)
ts1(end)
ts2(end)
%calcuating the sum, the minimum value and the average number of ts1
sum(ts1)
min(ts1)
mean(ts1)
%Creating tsRev
tsRev=linspace(1,0,100);
%Checking the first and last elements of tsRev
tsRev(1)
%Prob 2
ts3=ts1(3)
ts1to3=ts1(1:3)
ts3to1=ts1(3:-1:1)
%We already have a tsRev variable
tsSkip=ts1(1:2:end)
length(tsSkip)
ts1=ts1+1
ts1=ts1+1
ts1=ts1+1
ts1(1)
ts1(end)

Function File (if applicable)


Command Window Output (cut and paste output here)

7/11/14

Homework #2

ans =
100
ans =
100
ans =
0
ans =
0
ans =
1
ans =
1
ans =
50.0000
ans =
0
ans =
0.5000
ans =
6

Renan Santos

7/11/14

Homework #2

Renan Santos

1
ts3 =
0.0202
ts1to3 =
0 0.0101 0.0202
ts3to1 =
0.0202 0.0101

tsSkip =
Columns 1 through 11
0 0.0202 0.0404 0.0606 0.0808 0.1010 0.1212 0.1414 0.1616
0.1818 0.2020
Columns 12 through 22
0.2222 0.2424 0.2626 0.2828 0.3030 0.3232 0.3434 0.3636 0.3838
0.4040 0.4242
Columns 23 through 33
0.4444 0.4646 0.4848 0.5051 0.5253 0.5455 0.5657 0.5859 0.6061
0.6263 0.6465
Columns 34 through 44
0.6667 0.6869 0.7071 0.7273 0.7475 0.7677 0.7879 0.8081 0.8283
0.8485 0.8687
Columns 45 through 50
0.8889 0.9091 0.9293 0.9495 0.9697 0.9899

7/11/14

Homework #2

Renan Santos

ans =
50
ts1 =
Columns 1 through 11
1.0000 1.0101 1.0202 1.0303 1.0404 1.0505 1.0606 1.0707 1.0808
1.0909 1.1010
Columns 12 through 22
1.1111 1.1212 1.1313 1.1414 1.1515 1.1616 1.1717 1.1818 1.1919
1.2020 1.2121
Columns 23 through 33
1.2222 1.2323 1.2424 1.2525 1.2626 1.2727 1.2828 1.2929 1.3030
1.3131 1.3232
Columns 34 through 44
1.3333 1.3434 1.3535 1.3636 1.3737 1.3838 1.3939 1.4040 1.4141
1.4242 1.4343
Columns 45 through 55
1.4444 1.4545 1.4646 1.4747 1.4848 1.4949 1.5051 1.5152 1.5253
1.5354 1.5455
Columns 56 through 66
1.5556 1.5657 1.5758 1.5859 1.5960 1.6061 1.6162 1.6263 1.6364
1.6465 1.6566
Columns 67 through 77
1.6667 1.6768 1.6869 1.6970 1.7071 1.7172 1.7273 1.7374 1.7475
1.7576 1.7677
Columns 78 through 88
1.7778 1.7879 1.7980 1.8081 1.8182 1.8283 1.8384 1.8485 1.8586
1.8687 1.8788
8

7/11/14

Homework #2

Renan Santos

Columns 89 through 99
1.8889 1.8990 1.9091 1.9192 1.9293 1.9394 1.9495 1.9596 1.9697
1.9798 1.9899
Column 100
2.0000
ts1 =
Columns 1 through 11
2.0000 2.0101 2.0202 2.0303 2.0404 2.0505 2.0606 2.0707 2.0808
2.0909 2.1010
Columns 12 through 22
2.1111 2.1212 2.1313 2.1414 2.1515 2.1616 2.1717 2.1818 2.1919
2.2020 2.2121
Columns 23 through 33
2.2222 2.2323 2.2424 2.2525 2.2626 2.2727 2.2828 2.2929 2.3030
2.3131 2.3232
Columns 34 through 44
2.3333 2.3434 2.3535 2.3636 2.3737 2.3838 2.3939 2.4040 2.4141
2.4242 2.4343
Columns 45 through 55
2.4444 2.4545 2.4646 2.4747 2.4848 2.4949 2.5051 2.5152 2.5253
2.5354 2.5455
Columns 56 through 66
2.5556 2.5657 2.5758 2.5859 2.5960 2.6061 2.6162 2.6263 2.6364
2.6465 2.6566
Columns 67 through 77

7/11/14

Homework #2

Renan Santos

2.6667 2.6768 2.6869 2.6970 2.7071 2.7172 2.7273 2.7374 2.7475


2.7576 2.7677
Columns 78 through 88
2.7778 2.7879 2.7980 2.8081 2.8182 2.8283 2.8384 2.8485 2.8586
2.8687 2.8788
Columns 89 through 99
2.8889 2.8990 2.9091 2.9192 2.9293 2.9394 2.9495 2.9596 2.9697
2.9798 2.9899
Column 100
3.0000
ts1 =
Columns 1 through 11
3.0000 3.0101 3.0202 3.0303 3.0404 3.0505 3.0606 3.0707 3.0808
3.0909 3.1010
Columns 12 through 22
3.1111 3.1212 3.1313 3.1414 3.1515 3.1616 3.1717 3.1818 3.1919
3.2020 3.2121
Columns 23 through 33
3.2222 3.2323 3.2424 3.2525 3.2626 3.2727 3.2828 3.2929 3.3030
3.3131 3.3232
Columns 34 through 44
3.3333 3.3434 3.3535 3.3636 3.3737 3.3838 3.3939 3.4040 3.4141
3.4242 3.4343
Columns 45 through 55
3.4444 3.4545 3.4646 3.4747 3.4848 3.4949 3.5051 3.5152 3.5253
3.5354 3.5455
Columns 56 through 66
10

7/11/14

Homework #2

Renan Santos

3.5556 3.5657 3.5758 3.5859 3.5960 3.6061 3.6162 3.6263 3.6364


3.6465 3.6566
Columns 67 through 77
3.6667 3.6768 3.6869 3.6970 3.7071 3.7172 3.7273 3.7374 3.7475
3.7576 3.7677
Columns 78 through 88
3.7778 3.7879 3.7980 3.8081 3.8182 3.8283 3.8384 3.8485 3.8586
3.8687 3.8788
Columns 89 through 99
3.8889 3.8990 3.9091 3.9192 3.9293 3.9394 3.9495 3.9596 3.9697
3.9798 3.9899
Column 100
4.0000
ans =
3
ans =
4
>>

Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

11

7/11/14

Homework #2

Problem 3
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all
%Given x values
x=linspace(1,10,30);
%Calculating y
y=(2*x.^3)./(4*x+3);

%Calculating z
z=2*(x+3)+(10*x+2)./(3*x.^2);
%Printing Results
plot(x,y,'r')
xlabel('x')
ylabel('y')
hold on
plot(x,z,'k')
xlabel('x')
ylabel('y')

12

Renan Santos

7/11/14

Homework #2

Renan Santos

Function File (if applicable)


Command Window Output (cut and paste output here)
Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

13

7/11/14

Homework #2

Problem 4
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all
%Declaring Variables
A=input('Input the value for the variable A:');
B=input('Input the value for the variable B:');
aux=A;
%Printing values before the swap
fprintf('Before the swap, the values of A are:\n');
disp(A)
fprintf('Before the swap, the values of B are:\n');
disp(B)
%Swapping Values
A=B;
B=aux;
%Printing values after swapping
fprintf('After the swap, the values of A are:\n');
disp(A)
fprintf('After the swap, the values of B are:\n');
disp(B)

Function File (if applicable)


Command Window Output (cut and paste output here)
Input the value for the variable A:5
Input the value for the variable B:6
Before the swap, the values of A are:
5
Before the swap, the values of B are:
6
After the swap, the values of A are:
6
After the swap, the values of B are:
5
>>
14

Renan Santos

7/11/14

Homework #2

Renan Santos

Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

15

7/11/14

Homework #2

Renan Santos

Problem 5
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all
clf
%Prob 5 PART A
%Declaring Domain
t=(-5:0.05:1); %seconds
%Main Equation
y=t.^2+3*t+4;
%Calculating the maximum and minimum values for y
ymx=max(y);
ymn=min(y);
%Printing values and plotting graph
fprintf('The minimum and maximum values of y for the range of t
is %0.3f and %0.3f, respectively \n',ymn,ymx)
plot(t,y,'k')
xlabel('Time(sec)')
ylabel('Distance(meters)')
title('Tive vs Distance')
%Prob 5 PART B
%Derivating the equation and we get:
dy=2*t+3;

Function File (if applicable)


Command Window Output (cut and paste output here)
The minimum and maximum values of y for the range of t is 1.750 and 14.000,
respectively
>>

Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

16

7/11/14

Homework #2

17

Renan Santos

7/11/14

Homework #2

Renan Santos

Problem 6
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all

%Creating plots
%Subplot 1
subplot(1,2,1);
p=(1:1:100); %pressure (pascals)
R=1.1; %Radius of the tank(meters)
t=0.025; %thickness of the tank (meters)
sigma=p.*R/(2*t); %stress (pascals) *Main Equation*
plot(p,sigma,'b');
xlabel('Pressure(pascals)')
ylabel('Stress(pascals)')
title('Pressure vs Stress')
%Subplot 2
subplot(1,2,2);
p=4; %Pascals
R=2; %meters
t=(0.01:0.03:3); %meters
sigma=p*R*(2*t).^(-1); %stress (pascals) *Main Equation*
plot(t,sigma,'k');
xlabel('Thickness(meters)')
ylabel('Stress(pascals)')
title('Thickness vs Stress')

Function File (if applicable)


Command Window Output (cut and paste output here)
Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

18

7/11/14

Homework #2

19

Renan Santos

7/11/14

Homework #2

Renan Santos

Problem 7
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all
clf
%Declaring Variables
t=(0:0.2:3); % time (years)
n1=1.2; %Scale Parameters
n2=1.5;
n3=2.5;
b=1.2; %Shape parameter
%Main equation
R1=exp(-(t./n1).^(b));
R2=exp(-(t./n2).^(b));
R3=exp(-(t./n3).^(b));
%Plotting graph
plot(t,R1,'-r')
hold on
grid on
plot(t,R2,'--k')
hold on
plot(t,R3,'-bo')
legend('n1=1.2','n2=1.5','n3=2.5')
xlabel('Time(years)')
ylabel('Reliability')
title('Time vs Reliability')

Function File (if applicable)


Command Window Output (cut and paste output here)
Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

20

7/11/14

Homework #2

21

Renan Santos

7/11/14

Homework #2

Problem 8
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all
clf
%Declaring variables
a=0.5;
b=0.3;
theta=linspace(0,10*pi,100);
t=(0:1:1000);
%Main Equations
%Polar Coordinates
r=a*exp(b*theta);
%Cartesian Coordinates
x=a*exp(b*t).*cos(t);
y=a*exp(b*t).*sin(t);
%PART A
%Creating subplots
subplot(1,2,1);
polar(theta,r)
title('Polar Plot of a Spiral')
subplot(1,2,2);
plot(x,y)
title('Cartesian Plot of a Spiral')
%PART B
p1=a*exp(b*0); %point p1
p2=a*exp(b*2*pi); %point p2
p3=a*exp(b*4*pi);%point p3
ratio1=p2/p1;
ratio2=p3/p2;
%printing values
fprintf('The ratio 1 is %0.3f and the ratio 2 is %0.3f
\n',ratio1,ratio2)

22

Renan Santos

7/11/14

Homework #2

Renan Santos

Function File (if applicable)


Command Window Output (cut and paste output here)
The ratio 1 is 6.586 and the ratio 2 is 6.586
>>

Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

23

7/11/14

Homework #2

24

Renan Santos

7/11/14

Homework #2

Renan Santos

Problem 9
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all
clf
%declaring variables
m=150; %mass (kg)
g=9.81; %gravity (m/s^2)
%PART A
%declaring variables
t=(0:1:35); %Time(seconds)
c=13.5; %drag coefficient(kg/s)
v=((g*m)./c)*(1-exp((-c*t)./m));
plot(t,v,'b');
hold on
xlabel('Time(seconds)')
ylabel('Velocity(m/s)')
title('Time vs Velocity')
vp=(g*m/c)*(1-exp(-c*12/m));
fprintf('The velocity at 12s with c= 13.5 is %0.2f m/s \n',vp)

%PART B
c=9; %kg/s
v1=((g*m)./c)*(1-exp((-c*t)./m));
plot(t,v1,'--k');
vp=(g*m/c)*(1-exp(-c*12/m));
fprintf('The velocity at 12s with c=9 is %0.2f m/s \n',vp)
legend('c=13.5 kg/s','c=9 kg/s')

Function File (if applicable)


Command Window Output (cut and paste output here)
The velocity at 12s with c= 13.5 is 71.98 m/s
The velocity at 12s with c=9 is 83.92 m/s
>>

Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

25

7/11/14

Homework #2

26

Renan Santos

7/11/14

Homework #2

Problem 10
Comments for grader/additional information (if any)
Script File (should include pseudo code as comments)
clc
clear all
clf
%declaring variables
gin=5; %ksi
c=0.05;
t1=0.06; %seconds
t2=500; %seconds
w=(0.0001:1000); %s^-1
%Main Equations
Gp=gin*(1+(c/2)*log((1+(w.*t2).^2)./(1+(w.*t1).^2)));
Gdp=c*gin*(atan(w.*t2)-atan(w.*t1));
%Printing plots
subplot(2,2,1)
semilogx(w,Gp)
title('Dynamic Storage Modulus (Gp)')
xlabel('Frequency omega in inverse seconds')
ylabel('Gp in ksi')
subplot(2,2,2)
semilogx(w,Gdp)
title('Dynamic Loss Modulus (Gdp)')
xlabel('Frequency omega in inverse seconds')
ylabel('Gdp in ksi')
subplot(2,2,3)
plot(w,Gp)
title('Dynamic Storage Modulus (Gp)')
xlabel('Frequency omega in inverse seconds')
ylabel('Gp in ksi')
subplot(2,2,4)
plot(w,Gdp)
title('Dynamic Loss Modulus (Gdp)')
xlabel('Frequency omega in inverse seconds')
ylabel('Gdp in ksi')

27

Renan Santos

7/11/14

Homework #2

Renan Santos

Function File (if applicable)


Command Window Output (cut and paste output here)
Plot Window Output (you can save the plot and include it here save it
as a png, not a fig, or use a screen grab mac windows)

28

S-ar putea să vă placă și