2 x Figure 3 x + 35 CO2 Weighted Percentage 30 25 200 15 Weighted CO2 Emissions Combined Best Fit - Orange Diesel, Petrel, Diesembosed Beatlestit Petrol Diesel 000 20 10 20 narzo Shot on realme narzo 30 5G 30 Car Position & 0 00 40 50 80 D 60 2024 05 07 09:17
2 x Figure 3 x + 35 CO2 Weighted Percentage 30 25 200 15 Weighted CO2 Emissions Combined Best Fit - Orange Diesel, Petrel, Diesembosed Beatlestit Petrol Diesel 000 20 10 20 narzo Shot on realme narzo 30 5G 30 Car Position & 0 00 40 50 80 D 60 2024 05 07 09:17
Elements Of Electromagnetics
7th Edition
ISBN:9780190698614
Author:Sadiku, Matthew N. O.
Publisher:Sadiku, Matthew N. O.
ChapterMA: Math Assessment
Section: Chapter Questions
Problem 1.1MA
Related questions
Question
There is a small space between the orange and purple line could you please connect the two lines together also can you please make the purple line shorter and then connect the purple line to the orange line, please take out the box that says “Diesel, petrol, Diesel best fit, petrol best fit”. Also when ever I run this code the graph shows up but there are still errors that comes up could you please fix them when you are running this on MATLAB.
Please use this code on MATLAB and fix it.
% Sample data for Diesel and Petrol cars
carPosition = linspace(1, 60, 50); % Assumed positions of cars
% Fix the random seed for reproducibility
rng(50);
% 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
pDiesel = polyfit(carPosition, CO2Diesel, 3);
pPetrol = polyfit(carPosition, CO2Petrol, 3);
% 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;
% Split car positions for the two colored segments
splitIndex = round(length(carPosition) / 2);
% Plot combined best fit line (half-orange, half-purple)
plot(carPosition(1:splitIndex), combinedFit(1:splitIndex), 'Color', [1, 0.5, 0], 'LineWidth', 2); % Orange
plot(carPosition(splitIndex+1:end), combinedFit(splitIndex+1:end), 'Color', [0.5, 0, 1], 'LineWidth', 2); % 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('Combined Best Fit - Orange', 'Combined Best Fit - Purple', 'Petrol', 'Diesel');
% Optionally add an annotation box with specific text
annotation('textbox', [0.15, 0.75, 0.3, 0.1], 'String', 'Diesel, Petrol, Diesel Best Fit, Petrol Best Fit', 'FitBoxToText', 'on');
% Add grid lines
grid on;
hold off;
% Save the plot as an image (PNG format)
saveas(gcf, 'CO2_Emissions_Plot.png');
% Save workspace variables to a .mat file
save('CO2_Emissions_Data.mat', 'carPosition', 'CO2Diesel', 'CO2Petrol', 'combinedFit');
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 with 1 images
Recommended textbooks for you
Elements Of Electromagnetics
Mechanical Engineering
ISBN:
9780190698614
Author:
Sadiku, Matthew N. O.
Publisher:
Oxford University Press
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:
9780134319650
Author:
Russell C. Hibbeler
Publisher:
PEARSON
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:
9781259822674
Author:
Yunus A. Cengel Dr., Michael A. Boles
Publisher:
McGraw-Hill Education
Elements Of Electromagnetics
Mechanical Engineering
ISBN:
9780190698614
Author:
Sadiku, Matthew N. O.
Publisher:
Oxford University Press
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:
9780134319650
Author:
Russell C. Hibbeler
Publisher:
PEARSON
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:
9781259822674
Author:
Yunus A. Cengel Dr., Michael A. Boles
Publisher:
McGraw-Hill Education
Control Systems Engineering
Mechanical Engineering
ISBN:
9781118170519
Author:
Norman S. Nise
Publisher:
WILEY
Mechanics of Materials (MindTap Course List)
Mechanical Engineering
ISBN:
9781337093347
Author:
Barry J. Goodno, James M. Gere
Publisher:
Cengage Learning
Engineering Mechanics: Statics
Mechanical Engineering
ISBN:
9781118807330
Author:
James L. Meriam, L. G. Kraige, J. N. Bolton
Publisher:
WILEY