Documente Academic
Documente Profesional
Documente Cultură
Homework #2
Renan Santos
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
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)
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)
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
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)
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
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)
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;
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')
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')
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
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')
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
28