HW3Solutions - 9/18/08 1:00 PM F:\Matlab...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 9/18/08 1:00 PM F:\Matlab Projects\HW3\NMI—IW3num22.m 1 of 1 %Homework Number 3 %Prob1em Number 22 %Variable declarations E = 30E6; I = 0.163; L = 10; w = 100; x = 0:O.-5:10; [theta,MaxDis] = deflection(E,I,L,w,x) i l S' i x i 2 § 3 E E E E E § E i E a 3 § 2 E E f E E E % E 9/18/08 12:59 PM F:\Matlab Projects\HW3\deflection.m 1 of 1 function [theta,MaxDis] = deflection(E,I,L,w,x) %Notice the periods. They require elemental multiplication. displacement = ((—w*x.‘2)/(24*E*I)).*((6*L*2)—(4*L*x)+x.*2); MaxDis = max(abs(disp1acement)); theta = (w*LA3)/(6*E*I); plot(x,displacement) title('Def1ection of the beam') x1abel('Length (in)') ylabel('Displacement (in)') aiqanWm-VfimfimY-«m xmwmwmwmmmwm)memwmmmmwm.mmmmmw Deflection of the beam ‘ i: "tx;1)li.lvt[§.(§§zz§§2ki§735;;32235356$;igxiizufiyflsfizksz2,..Eégsgéfis:EnkEfiésEéuEygi5:ElufisflLESE:a5652?.is.igg5.755%».uuugfiéfififififikfifiagggfi 10 5 Length (in) -0.005 -0.01 -0.015 -0.02 -0.025 —0.03 E: EmEmomamfi. 1 of 1 MATLAB Command Window 9/18/08 1:09 PM theta 0.0034 MaxDis 0.0256 >> 9/18/08 1:03 PM F:\Matlab Projects\HW3\NMHW3num25.m 1 of 1 %Homework Number 3 %Prob1em 25 from Chapter 3 fid = fopen('xy.dat'); %Opening the file and configuring A = fscanf(fid,'%f'); %it into a 100 by 2 matrix. B = reshape(A,2,lOO)'; fclose(fid); x = B(:,1); y = B(:,2); %Assigning the columns to x and y t = pi*(sin(x)+cos(x)); %Creating t y_bar = mean(y); %Finds the average mean of y %NOTE: y_bar is a scalar where x, y, and t are all vectors. %You can graph this way but you can't mix vector sizes. plotData(x,t,y,y~bar) E E g E E E E i E E E E E E E 2 E a E 5 E E srammm«w:r.7xrmmmm§twicmvmmmmwmnmn 9/18/08 1:03 PM F:\Matlab Projects\HW3\plotData.m 1 of 1 function plotData(x,t,y,y_bar) plot(x,t,'b—',x,y,'go',x,y_bar,'r——') 1egend('x and t', 'x and y', 'y average',3) title('Noise versus Signal') Noise versus Signal xandt xandy 0 e 9 m e V a y _ _ _ _ _ 9/18/08 1:04 PM F:\Matlab Projects\HW3\NMHW3num3.m 1 of 2 %Homework Number 3 %Prob1em Number 3 %Varib1e definitions x=[231—2—l325314—2]; A = [1 —3 —1 2; -2 2 —3 1; —1 2 -3 1; 3 -2 1 4]; B = [—2 1 2 3; 3 -2 1 2; 1 —1 3 2; 2 -4 3 1]; fprintf(lPart A') suma=0; . %Initialize sum as zero for i = 1:5 %Incrementing from 1 to 5 . g a = 1*2+4*i; ” suma = suma + a; %suma = 0 initially for the first run but end %is reset to equal a. Then for the second %run it equals old a (suma) plus the new suma %a. It continues like this. fprintf('Part B') sumb=0; for i = 2:5 b = x(i-1)*x(i); %Same concept as above but we are using sumb = sumb + b; %i as the subscript. This says that the end %i-1 term of x times the ith term of x %equals b. The summation idea is the same i g sumb %as above. g fprintf('Part C') sumc=0; for i = 2:2:10 %The only difference here is you are c = x(i)‘2; %altering your increment. The default sumc = sumc + c; %is one but you are changing it to two. end sumc fprintf('Part D') sumd=0; for i = 1:4 %We have nested for loops here. So the for j = 1:4 %order of operations goes i = 1, then d = A(i,j)*B(i,j); %j = 1, j = 2, etc... then back to i = 2 sumd = sumd + d; %and then j = 1, j = 2, etc... The "nested" end %for loop will run completely for each end %ith iteration. sumd fprintf('Part E') prode=1; %Define as 1! for i = 1:4 e = x(i)*2; prode = prode*e; %Exact same as the other loops except 2 of 2 F:\Matlab Projects\HW3\NMHW3num3.m 9 n .1 Y 1 P .l t m m 0/0 M P 4 0 l 8 0 w n m 9 e e d O r p l of 1 MATLAB Command Window 9/18/08 1:05 PM Part A suma 115 Part B sumb Part C SUIIIC 48 Part D sumd Part E e d O r P 144 >> 9/18/08 1:07 PM F:\Matlab Projects\HW3\NMHW3num43.m %Homework Number 3 %Problem 43 from Chapter 3 %User inputs d v h input('What is the diameter?\n') input('What is the velocity?\n') cylhtc(d,v) 1 of 1 9/18/08 1:07 PM F:\Matlab Projects\HW3\cylhtc.m function h = cylhtc(d,v) %Some variable declarations rho = 1.204; mu = 1.82E—5; cofp = 1.007; k = 26.3E—3; Pr = mu*cofp/k; %Prandtl number Re rho*v*d/mu %Conditional if statements for the Reynolds number. %The "else" is for any Reynolds number not defined %in the chart. It returns Undefined for the values. if .4<Re & Re<=4 C = .989; m = .330; else if Re>4 & Re<=40 C = .911; m = .385; else if Re>40 & Re<=4000 C = .683; m = .466; else if Re>4000 & Re<=40000 C = .193; m = .618; else if Re>40000 & Re<=400000 C = .027; m = .805; else C = 'Undefined' m = 'Undefined' end end end end end %If the Reynolds number isn't in the chart (i.e. less %than .4 or greater than 400000), it won't calculate. if Re>400000 I Re<=.4 h = 'Not able to calculate h'; %Otherwise, it calculates h using the given C and m %from the if statements. else Nu = c*(Re*m)*(Pr‘(1/3)); h = k*Nu/d; end %The "else" in the big set of loops isn't required. I %did it so the program wouldn't crash assuming you picked %Values for d and v that gave a Reynolds number outside 1 of 2 g 9 i . g fr 3; 9/18/08 1:07 PM F:\Matlab Projects\HW3\cylhtc.m 2 of 2 __.________________________________________—__ %of the chart. Consequently, the last if—else loop isn't %required either. ammmfivmmwflv; 9/18/08 1:07 PM MATLAB Command Window 1 of 2 W What is the diameter? .01 d: 0.0100 What is the velocity? 10 10' Re = 6.6154e+003 10.3355 What is the diameter? 100 d: 100 What is the velocity? 1000 1000 Re = 6.6154e+009 C: Undefined m: Undefined 2 of 2 MATLAB Command Window 9/18/08 1:07 PM Not able to calculate h >> ...
View Full Document

Page1 / 15

HW3Solutions - 9/18/08 1:00 PM F:\Matlab...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online