Weighted CO2 Emmisions 50 40 30 20 20 CO2 Weighted Percentage о о 10 0 0 0 о 8 -10 0 10 20 30 Car Position 40 о Diesel Petrol Diesel Best Fit Petrol Best Fit 50 50 60
Weighted CO2 Emmisions 50 40 30 20 20 CO2 Weighted Percentage о о 10 0 0 0 о 8 -10 0 10 20 30 Car Position 40 о Diesel Petrol Diesel Best Fit Petrol Best Fit 50 50 60
Refrigeration and Air Conditioning Technology (MindTap Course List)
8th Edition
ISBN:9781305578296
Author:John Tomczyk, Eugene Silberstein, Bill Whitman, Bill Johnson
Publisher:John Tomczyk, Eugene Silberstein, Bill Whitman, Bill Johnson
Chapter31: Gas Heat
Section: Chapter Questions
Problem 5RQ: The specific gravity of natural gas is A. 0.08. B. 1.00. C. 0.42. D. 0.60.
Question
Could you please use this code to make the graph that you see in the picture.
Keep the color of the lines the same and the circle the same basically make the orange and purple line that you see with the same curve. Do not make the lines too curvy just make it a little bit curvy just like you see in the picture.
Use this code on MATLAB and fix it. Please make sure that every time you run the code on MATLAB it doesn’t show different curves on the line. Please it shows the same line when you run it.
% Sample data for Diesel and Petrol cars
carPosition = linspace(1, 60, 50); % Assumed positions of cars
% Use the 'seed' function instead of 'rng'
seed = 50; % Define your seed here
rand('seed',seed);
% Assumed CO2 emissions for Diesel and Petrol
CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel
CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol
% Fit polynomial curves with a reduced degree of 2
pDiesel = polyfit(carPosition, CO2Diesel, 2);
pPetrol = polyfit(carPosition, CO2Petrol, 2);
% Generate points for best fit lines
fitDiesel = polyval(pDiesel, carPosition);
fitPetrol = polyval(pPetrol, carPosition);
% Combined best fit
combinedFit = (fitDiesel + fitPetrol) / 2;
% Plotting the data
figure; hold on;
% Define the split index and shorten the purple line
splitIndex = round(length(carPosition) / 2);
shortenIndex = round(length(carPosition) * 0.8);
% Plot the combined best fit line (connect orange and purple, purple line shorter)
plot(carPosition(1:shortenIndex), combinedFit(1:shortenIndex), 'Color', [1, 0.5, 0], 'LineWidth', 2); % Orange to shorter purple
plot(carPosition(shortenIndex:end), combinedFit(shortenIndex:end), 'Color', [0.5, 0, 1], 'LineWidth', 2); % Shortened Purple
% Petrol data
scatter(carPosition, CO2Petrol, 'o', 'MarkerEdgeColor', [0 0.5 1]); % Blue for Petrol
% Diesel data
scatter(carPosition, CO2Diesel, 'o', 'MarkerEdgeColor', [1 0.5 0]); % Orange for Diesel
% Customize the plot
xlabel('Car Position');
ylabel('CO2 Weighted Percentage');
title('Weighted CO2 Emissions');
% Adjust axis limits
xlim([1 60]);
ylim([15 35]);
% Add a legend with custom names
legend('Diesel Best Fit', 'Petrol Best Fit', 'Petrol', 'Diesel');
% Add grid lines
grid on; hold off;
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Recommended textbooks for you
Refrigeration and Air Conditioning Technology (Mi…
Mechanical Engineering
ISBN:
9781305578296
Author:
John Tomczyk, Eugene Silberstein, Bill Whitman, Bill Johnson
Publisher:
Cengage Learning
Refrigeration and Air Conditioning Technology (Mi…
Mechanical Engineering
ISBN:
9781305578296
Author:
John Tomczyk, Eugene Silberstein, Bill Whitman, Bill Johnson
Publisher:
Cengage Learning