Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- review.m
- clear;clc
- disp('ENGR 1181')
- disp('Midterm 2 Review')
- disp('----------------')
- disp('Problem 1')
- x = 10;
- y = (log10(x) * log(x)) / exp(1.1); % log10 is log and log is ln
- fprintf('The answer is %.2f.\n', y)
- x = 45;
- y = (cosd(x) + sind(x)) / (x - 44); % cosd and sind for degrees
- fprintf('The answer is %.2f.\n', y)
- disp('---------')
- % Part of problem 2 is in a seperate function file (problem2.m).
- disp('Problem 2')
- t = input('Input the values of t.\nt = ');
- k = input('Input the values of k.\nk = ');
- [y, df] = problem2(t, k);
- fprintf('y(t) = ')
- fprintf('%.2e ', y)
- fprintf('\ndf(k) = ')
- fprintf('%.2f ', df)
- fprintf('\n');
- disp('---------')
- % Problem 3
- subplot(1, 2, 1)
- fplot('P + P^2 + 2', [-2 2])
- subplot(1, 2, 2)
- fplot('(P + 1) / (P - 1)', [-2 2])
- % ---------
- % Problem 4
- fMeasured = [3.8 1.01 15.2 32.8 10.6];
- m = [1 0.25 4 9 3];
- a = 3.7;
- fCalculated = m .* a;
- figure
- hold on
- plot(m, fCalculated, 'r-')
- plot(m, fMeasured, 'bx')
- hold off
- title('Force v. Mass on Mars')
- xlabel('Mass (kg)')
- ylabel('Force (N)')
- legend('Calculated force', 'Measured force')
- % ---------
- disp('Problem 5')
- x = 1:10;
- y = x .^ 2 + x;
- y2 = y .* x + x .^ 2 + y;
- y3 = y2 .* (y ./ 2) + (2 ./ x) + ((x .* y) ./ y2) + x;
- figure
- hold on
- plot(x, y, 'r-')
- plot(x, y2, 'b--')
- plot(x, y3, 'k:')
- hold off
- legend('y', 'y2', 'y3')
- axis([1 10 0 1000])
- fprintf('| x | y | y2 | y3 |\n')
- fprintf('| %i | %.2f | %.2f | %.2f |\n', [x; y; y2; y3])
- disp('---------')
- % Problem 6
- temp = 10:10:50;
- expA = [1.15 2.86 3.11 4.1 5.2];
- expB = [1.11 2.8 3.05 3.9 6.9];
- figure
- subplot(1, 2, 1)
- hold on
- plot(temp, expA, 'rx')
- plot(temp, expB, 'bo')
- hold off
- title('Data v. Temperature')
- legend('Experiment A', 'Experiment B')
- xlabel('Temperature')
- ylabel('Data')
- error = ((expA - expB) ./ expA) * 100;
- subplot(1, 2, 2)
- plot(temp, error)
- title('Error v. Temperature')
- xlabel('Temperature')
- ylabel('Error Percent')
- % ---------
- % Problem 7
- V = 100:50:900;
- y = 1.4;
- a = 1000;
- p_ptCalc = zeros(1, length(V));
- for i = 1:length(V)
- p_ptCalc(i) = (1 + ((y - 1) / 2) * (V(i) / a)^2) ^ -(y / (y - 1));
- end
- p_ptExp = [.99 .97 .93 .9 .83 .75 .72 .64];
- M = .1:.1:.8;
- figure
- hold on
- plot(V / a, p_ptCalc, 'r-')
- plot(M, p_ptExp, 'b*')
- hold off
- legend('Calculated', 'Experimental')
- title('Pressure v. Mach')
- xlabel('Mach')
- ylabel('Pressure')
- % ---------
- disp('Problem 8')
- a = input('What is a?\na = ');
- rho = 0.0023;
- R = 1716;
- % I didn't really understand the directions on what it wanted for T
- T = randi([480 520]);
- if a == 1
- P = rho * R * T;
- elseif a == 2
- P = rho * R * T ^ 1.01;
- elseif a == 3
- P = rho ^ 1.01 * R * T;
- elseif a > 1.2 && a <= 1.5
- P = rho * R * T ^ 1.05;
- else
- disp('Input error. Invalid value for a.')
- end
- % In the else case, P is never set, which would cause the fprintf
- % to throw an error when it tries to access P, so I check to see if
- % P is set before I call fprintf.
- if exist('P', 'var')
- fprintf('P = %.2f\n', P)
- end
- disp('---------')
- disp('Problem 9')
- a = zeros(4);
- for i = 1:size(a, 1)
- for j = 1:size(a, 2)
- if i == j
- a(i, j) = j;
- elseif j > i
- a(i, j) = 2 * j;
- elseif j < i
- a(i, j) = -j;
- end
- end
- end
- disp(a)
- disp('---------')
- % Part of problem 10 is in a seperate function file (problem10.m).
- disp('Problem 10')
- rho = input('What is rho?\nrho = ');
- P = input('What is P?\nP = ');
- n = input('How many cases?\nn = ');
- for i = 1:n
- fprintf('What are the values for velocity for case %i?\n', i)
- V = input('V = ');
- Po = problem10(P, rho, V)';
- fprintf('Case %i Po = ', i)
- fprintf('%.2f ', Po)
- fprintf('\n')
- end
- disp('----------')
- % Problem 11
- x = 0:6;
- y = zeros(1, length(x));
- for i = 1:length(x)
- if x(i) >= 0 && x(i) < 2
- y(i) = x(i) ^ 2 + .5 * x(i);
- elseif x(i) >= 2 && x(i) < 4
- y(i) = 2 * x(i) ^ 2 + 2;
- else
- y(i) = 5 * x(i) - 5;
- end
- end
- figure
- plot(x, y)
- % ----------
- problem2.m
- function [y, df] = problem2(t, k)
- % Usage: problem2(t, k)
- % Returns y(t) and df(k)
- y = (exp(-t) .* sin(2 * t) .^ 2) ./ (2 * (t + 1));
- df = ((k .^ 4 + k .^ 3) ./ (k + 2)) + ((k .^ 2 + k) ./ (k + 1));
- end
- problem10.m
- function Po = problem10(P, rho, V)
- % Usage: problem10(P, rho, V)
- % Returns the bernoulli equation for the given values.
- Po = P + .5 * rho .* V .^ 2;
- end
- command output
- ENGR 1181
- Midterm 2 Review
- ----------------
- Problem 1
- The answer is 0.77.
- The answer is 1.41.
- ---------
- Problem 2
- Input the values of t.
- t = 0:10
- Input the values of k.
- k = 1:5
- y(t) = 0.00e+00 7.60e-02 1.29e-02 4.86e-04 1.79e-03 1.66e-04 5.10e-05 5.59e-05 1.54e-06 3.48e-06 1.72e-06
- df(k) = 1.67 8.00 24.60 57.33 112.14
- ---------
- Problem 5
- | x | y | y2 | y3 |
- | 1 | 2.00 | 5.00 | 8.40 |
- | 2 | 6.00 | 22.00 | 69.55 |
- | 3 | 12.00 | 57.00 | 346.30 |
- | 4 | 20.00 | 116.00 | 1165.19 |
- | 5 | 30.00 | 205.00 | 3081.13 |
- | 6 | 42.00 | 330.00 | 6937.10 |
- | 7 | 56.00 | 497.00 | 13924.07 |
- | 8 | 72.00 | 712.00 | 25641.06 |
- | 9 | 90.00 | 981.00 | 44155.05 |
- | 10 | 110.00 | 1310.00 | 72061.04 |
- ---------
- Problem 8
- What is a?
- a = 2
- P = 2172.05
- ---------
- Problem 9
- 1 4 6 8
- -1 2 6 8
- -1 -2 3 8
- -1 -2 -3 4
- ---------
- Problem 10
- What is rho?
- rho = .0023
- What is P?
- P = 14.7/144
- How many cases?
- n = 2
- What are the values for velocity for case 1?
- V = 70:100
- Case 1 Po = 5.74 5.90 6.06 6.23 6.40 6.57 6.74 6.92 7.10 7.28 7.46 7.65 7.83 8.02 8.22 8.41 8.61 8.81 9.01 9.21 9.42 9.63 9.84 10.05 10.26 10.48 10.70 10.92 11.15 11.37 11.60
- What are the values for velocity for case 2?
- V = 100:120
- Case 2 Po = 11.60 11.83 12.07 12.30 12.54 12.78 13.02 13.27 13.52 13.77 14.02 14.27 14.53 14.79 15.05 15.31 15.58 15.84 16.11 16.39 16.66
- ----------
- graphs
- http://imgur.com/a/LAFHv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement