how to graph a data array that is based on another data array

28 visualizaciones (últimos 30 días)
Kyle
Kyle el 29 de Oct. de 2024 a las 21:04
Respondida: Umar el 30 de Oct. de 2024 a las 0:23
I have an assignment in economy that asks to pick the best option based on present worth analysis of multiple different highway building projects. One detail in these projects is the amount of money value for saving a human life, which is not a single value but a range of 100000-500000$. The other detail is the value for preventing injury, which is 1/4*SavingLife - 2/3*SavingLife
Each project has different amounts of lives saved and injuries prevented (like 11 lives and 2 prevented injuries), and i want to graph the full analysis using the present value (a constant that i already have) with both arrays added to the total, but im not sure how to get all values to be accounted for both details.
The values dont need to be converted to Present Value

Respuestas (1)

Umar
Umar el 30 de Oct. de 2024 a las 0:23

Hi @Kyle,

After reviewing your comments, let me break down the key components and formulate a MATLAB code that incorporates your requirements.

Present Worth Analysis: This method helps evaluate the profitability of different projects by comparing their net present values (NPV).

Value of Saving a Human Life: You have a range for this value ($100,000 to $500,000).

Value of Preventing Injury: Defined as a function of the saving life value.

Data Structure: You have multiple projects, each with specific metrics on lives saved and injuries prevented.

For each project, compute the total monetary value based on lives saved and injuries prevented and use MATLAB to visualize the findings. Here is an updated MATLAB code that calculates the total present worth based on your criteria:

% Define constants
savingLifeRange = [100000, 500000]; % Range for saving a human life
injuryFactor = [1/4, -2/3]; % Coefficients for injury value calculation
% Sample data for projects (number of lives saved and injuries prevented)
projects = [
  struct('livesSaved', 11, 'injuriesPrevented', 2),
  struct('livesSaved', 15, 'injuriesPrevented', 3),
  struct('livesSaved', 8, 'injuriesPrevented', 1)
];
% Initialize arrays to store results
presentWorthValues = zeros(length(projects), 1);
lowerBoundValues = zeros(length(projects), 1);
upperBoundValues = zeros(length(projects), 1);
% Calculate present worth for each project
for i = 1:length(projects)
  % Calculate the value from saving lives
  livesValueLower = projects(i).livesSaved * savingLifeRange(1);
  livesValueUpper = projects(i).livesSaved * savingLifeRange(2);
    % Calculate the value from preventing injuries
    injuriesValueLower = projects(i).injuriesPrevented * ...
        (injuryFactor(1) * savingLifeRange(1) + injuryFactor(2) * 
        savingLifeRange(1));
        injuriesValueUpper = projects(i).injuriesPrevented * ...
        (injuryFactor(1) * savingLifeRange(2) + injuryFactor(2) * 
         savingLifeRange(2));
      % Total present worth calculations
      lowerBoundValues(i) = livesValueLower + injuriesValueLower;
      upperBoundValues(i) = livesValueUpper + injuriesValueUpper;
      % Store total present worth (using midpoint for simplicity)
      presentWorthValues(i) = (lowerBoundValues(i) + upperBoundValues(i)) / 2;
  end
% Display results
disp('Project Results:')
for i = 1:length(projects)
  fprintf('Project %d: Lives Saved: %d, Injuries Prevented: %d\n', ...
          i, projects(i).livesSaved, projects(i).injuriesPrevented);
  fprintf('Total Present Worth (Lower Bound): $%.2f\n', lowerBoundValues(i));
  fprintf('Total Present Worth (Upper Bound): $%.2f\n', upperBoundValues(i));
  fprintf('Average Present Worth: $%.2f\n\n', presentWorthValues(i));
end
% Plotting results
figure;
bar(presentWorthValues);
xlabel('Project Number');
ylabel('Average Present Worth ($)');
title('Average Present Worth of Highway Projects');
grid on;

Please see attached.

So, after going through above code, you will find a range setup for saving a life and factors for injury calculation. Information stored about each project in a structured format, calculated the lower and upper bounds of the total present worth based on lives saved and injuries prevented which outputs calculated values to the console. Finally, a bar graph represents the average present worth of each project. If applicable, you might also want to include external costs or benefits associated with highway projects to enhance your analysis.

Please let me know if you have any further questions.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by