Contents

Aaron Klapheck

% Ch 5. Assignment #11       due 11/21
clear, clc
Date = date
Date =

12-Dec-2007

Problem 2

% GIVEN

% Costs:
% Fixed (in $ per year)
%   2045000
% variable (in $ per gallon of product)
%   material -  0.62
%   energy   -  0.24
%   labor    -  0.16
% Total_cost ($) = fixed + (material+energy+labor)*Q

% Q = 6*10^6 - 1.1*10^6*P , where P is selling price ($ per gallon),
% and Q is the sales quantity (gallons).
% Solve for P: P = (6*10^6 - Q)/1.1*10^6
% P*Q = ($/gallon)*(gallons) = Revenue ($) = ((6*10^6 -Q)/(1.1*10^6))*Q
% Note: profit = revenue - cost.

% PLOT

% Plot Total_cost vs. Q and Revenue vs. Q.

% Given
material = 0.62; energy = 0.24; labor = 0.16; fixed = 2045000;
% Set up range of Q.
Q = [0:100:10^7];
Total_cost = fixed + (material+energy+labor)*Q;
Revenue = ((6*10^6 -Q)/(1.1*10^6)).*Q;

% General plot
% The purpose of this plot is to get an idea of what the graph looks like.

plot(Q, Total_cost, Q, Revenue), grid, xlabel('Q'), ...
    title('Total Cost and Revenue vs. Sales Quantity'), ...
    legend('Cost($) vs. Q(gal)', 'Revenue($) vs. Q(gal)'), ...
    ylabel('Cost and Revenue')

Problem 2 - fist break even point (the one on the left)

plot(Q, Total_cost, Q, Revenue), grid, xlabel('Q'),  ...
    title('Total Cost and Revenue vs. Sales Quantity'), ...
    legend('Cost($) vs. Q(gal)', 'Revenue($) vs. Q(gal)'), ...
    ylabel('Cost and Revenue'),
    axis([5*10^5 5.3*10^5 2.5*10^6 2.6*10^6]), ...
    [Q_1, Revenue_1] = ginput(1)
Q_1 =

  5.1573e+005


Revenue_1 =

  2.5709e+006

Problem 2 - second break even point (the one on the right)

plot(Q, Total_cost, Q, Revenue), grid, xlabel('Q'),  ...
    title('Total Cost and Revenue vs. Sales Quantity'), ...
    legend('Cost($) vs. Q(gal)', 'Revenue($) vs. Q(gal)'), ...
    ylabel('Cost and Revenue'),
    axis([4.3*10^6 4.4*10^6 6.4*10^6 6.6*10^6]), ...
    [Q_2, Revenue_2] = ginput(1)
Q_2 =

  4.3623e+006


Revenue_2 =

  6.4944e+006

Problem 2 - maximum profit and state range

plot(Q, Total_cost, Q, Revenue), grid, xlabel('Q'),  ...
    title('Total Cost and Revenue vs. Sales Quantity'), ...
    legend('Cost($) vs. Q(gal)', 'Revenue($) vs. Q(gal)'), ...
    ylabel('Cost and Revenue'),
    axis([2.9*10^6 3.1*10^6 7*10^6 10*10^6]), ...
    [Q_max, Revenue_max] = ginput(1)

% Range of Q is from Q_1 to Q_2
Range_of_Q_for_profitablility = [Q_1, Q_2]
Q_max =

  3.0002e+006


Revenue_max =

  8.1798e+006


Range_of_Q_for_profitablility =

  1.0e+006 *

    0.5157    4.3623

Problem 3

% Graphicaly find the roots of the given polynomial.


x = [-10:0.01:10];
p = [4, 3, -95, 5, -10, 80];

% General plot
plot(x, polyval(p,x)), title('Finding Roots of a Polynomial'), grid, ...
    xlabel('x'), ylabel('y = 4x^5+3x^4-95x^3+5x^2-10x+8')

Problem 3 - Use plot to find first root

plot(x, polyval(p,x)), title('Finding Roots of a Polynomial'), grid, ...
    xlabel('x'), ylabel('y = 4x^5+3x^4-95x^3+5x^2-10x+8'), ...
    axis([-5.4 -5.2 -0.1 0.1]), [x1_root, y1] = ginput(1)
x1_root =

   -5.3094


y1 =

 -2.9240e-004

Problem 3 - Use plot to find second root

plot(x, polyval(p,x)), title('Finding Roots of a Polynomial'), grid, ...
    xlabel('x'), ylabel('y = 4x^5+3x^4-95x^3+5x^2-10x+8'), ...
    axis([0.8 1 -0.1 0.1]), [x2_root, y2] = ginput(1)
x2_root =

    0.9459


y2 =

 -8.7719e-004

Problem 3 - Use plot to find third root and double check

plot(x, polyval(p,x)), title('Finding Roots of a Polynomial'), grid, ...
    xlabel('x'), ylabel('y = 4x^5+3x^4-95x^3+5x^2-10x+8'), ...
    axis([4.4 4.5 -0.1 0.1]), [x3_root, y3] = ginput(1)


% Using graphs: found roots to be at the x values: -5.3094, 0.946, and 4.474.

% Double check
Actual_root_of_polynomial = roots(p)
Graphical_root_of_polynomial = [x1_root, x2_root, x3_root]
x3_root =

    4.4741


y3 =

 -2.9240e-004


Actual_root_of_polynomial =

  -5.3094          
   4.4740          
   0.9461          
  -0.4303 + 0.8395i
  -0.4303 - 0.8395i


Graphical_root_of_polynomial =

   -5.3094    0.9459    4.4741

Problem 6

% Given
% V(t) = 10^9 + 10^8*(1 - exp(-t/100)) - 10^7*t, Where
% V is the water volume in liters
% t is the time in days

% 50% of 10^9 = 5*10^8

% Plot V(t) vs. t.

t = [0:1:100];
V = 10^9 + 10^8*(1 - exp(-t/100)) - 10^7*t;
plot(t, V), axis([0 100 4.9*10^8 5.1*10^8]), ...
    Title('Water Volume in Reservoir vs. Time'), ...
    xlabel('Time (Days)'), ylabel('Water Volume (Liters)'), grid, ...
    [days, liters_of_water] = ginput(1)
Warning: Could not find an exact (case-sensitive) match for 'Title'. C:\MATLAB701\toolbox\matlab\graph2d\title.m is a case-insensitive match and will be used instead.  You can improve the performance of your code by using exact name matches and we therefore recommend that you update your usage accordingly.  Alternatively, you can disable this warning using warning('off','MATLAB:dispatcher:InexactMatch').

days =

   54.4931


liters_of_water =

  4.9991e+008

Problem 9

% Given:
A = [0, -8, 6; 5, -4, 3; 10, -1, 1; 15, 1, 0; 20, 2, -1]

% plot column 1 vs. column 2 and 3 of matrix A.
plot(A(:, 1),A(:, 2:3)), Title('Forces Applied for a Given Time'), ...
    xlabel('Time (s)'), ylabel('Force (N)')
A =

     0    -8     6
     5    -4     3
    10    -1     1
    15     1     0
    20     2    -1

Problem 11

x = [0:0.01:2*pi];
y = tan(2*x);
subplot(1,2,1)
plot(x, y), title('tan(2x) vs. x'), xlabel('x'), ylabel('tan(2x)')


x = [0:0.01:2*pi];
y = (2*tan(x))./(1-tan(x).^2);
subplot(1,2,2)
plot(x, y), title('2tan(x)/(1-tan(x)^2) vs. x'), xlabel('x'), ...
    ylabel('2tan(x)/(1-tan(x)^2)')

% They look identical.

Problem 14

% Steady state value of y is 1. 98% of 1 is 0.98, where y is defined as:
% y = 1 - exp(-bt) equation #1

t = [0:0.01:30];
c = [1:1:20];

y_98 = 0.98

b_1 = c(1);
y_1 = 1 - exp(-b_1.*t);

b_10 = c(10);
y_10 = 1 - exp(-b_10.*t);

b_2 = c(2);
y_2 = 1 - exp(-b_2.*t);

subplot(1,1,1)
plot(t, y_1, t, y_2, t, y_10, t, y_98, '--'), axis([0 6 0 2]), ...
    title('(1 - exp(-bt)) vs. t at Various Values of b'), ...
    xlabel('Time'), ylabel('1 - exp(-bt)'), grid, ...
    legend('1 - exp(-t)', '1 - exp(-10t)', '1 - exp(-20t)', 'y = 0.98')

% Used graph to get the following information for equation #1.
% When b = 1,  98% of y occurs at x = 4
% When b = 2,  98% of y occurs at x = 2
% When b = 10,  98% of y occurs at x = 0.4
y_98 =

    0.9800

Problem 15

t = [0:0.01:10];
x = 10.*exp((-0.5).*t).*sin(3.*t + 2);
y = 7.*exp((-0.4).*t).*cos(5.*t - 3);

plot(t, x, t, y), xlabel('Time'), ylabel('Oscillations and Vibrations'), ...
    title('Electical Oscillations and Machine Vibrations vs. Time'), ...
    legend('Electrical Circuit Oscillations', 'Machine Vibrations')