Figure 1 File Edit View Insert Tools Desktop Window Help □ X 16 EUN 35 4\D incl se Ce ( о 0 30 Ο 25 Weighted CO2 Emissions Combined Best Fit - Orange Combined Best Fit - Purple Petrol Diesel X W N OO CO2 Weighted Percentage cti you ons os in ( O 20 20 0 O о 0 0 og 80 о 0 8 00 0 о O 00 20 ves rPo 0 arPo 00 15 5 10 15 or b (pDiesel, carPosition); (pPetrol, carPosition); iesel + fitPetrol) / 2; о O о a O ф о O о 25 30 35 Car Position Ο O O O 45 45 10 40 index and shorten the purple line length (car Position) / 2); donathasDeaitionl ٥١٠ 50 50 55 60 60 P sh sp CO2 Weighted Percentage igure 1 Edit View Insert Tools Desktop Window Help 35 200 Weighted CO2 Emissions Combined Best Fit-Orange Combined Best Fit - Purple o 0 фо ° о 0 Petrol Diesel C O 880 0 8 15 5 10 15 20 25 30 35 40 45 50 55 60 Car Position carfosition); Figure 1 Edit View Insert Tools Desktop Window Help CO2 Weighted Percentage 35 D 20 O 0 0 0 о 0 Weighted CO2 Emissions Combined Best Fit - Orange Combined Best Fit-Purple Petrol Diesel о 8 000 ° ° о 15 5 10 15 20 25 30 35 40 45 50 55 60 Car Position 1 carPosition);
Figure 1 File Edit View Insert Tools Desktop Window Help □ X 16 EUN 35 4\D incl se Ce ( о 0 30 Ο 25 Weighted CO2 Emissions Combined Best Fit - Orange Combined Best Fit - Purple Petrol Diesel X W N OO CO2 Weighted Percentage cti you ons os in ( O 20 20 0 O о 0 0 og 80 о 0 8 00 0 о O 00 20 ves rPo 0 arPo 00 15 5 10 15 or b (pDiesel, carPosition); (pPetrol, carPosition); iesel + fitPetrol) / 2; о O о a O ф о O о 25 30 35 Car Position Ο O O O 45 45 10 40 index and shorten the purple line length (car Position) / 2); donathasDeaitionl ٥١٠ 50 50 55 60 60 P sh sp CO2 Weighted Percentage igure 1 Edit View Insert Tools Desktop Window Help 35 200 Weighted CO2 Emissions Combined Best Fit-Orange Combined Best Fit - Purple o 0 фо ° о 0 Petrol Diesel C O 880 0 8 15 5 10 15 20 25 30 35 40 45 50 55 60 Car Position carfosition); Figure 1 Edit View Insert Tools Desktop Window Help CO2 Weighted Percentage 35 D 20 O 0 0 0 о 0 Weighted CO2 Emissions Combined Best Fit - Orange Combined Best Fit-Purple Petrol Diesel о 8 000 ° ° о 15 5 10 15 20 25 30 35 40 45 50 55 60 Car Position 1 carPosition);
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
Question
The picture that has two graphs are generated by this code. Every time I run it on MATLAB it keeps generating graphs with different curves. The picture that shows one graph is the curve that I want to keep. Please keep the color of the lines and the circles and keep the title of the graph the same. I want everything to be the same except I want the line to look exactly like the picture with one graph on it.
Use this code on MATLAB and fix it and then send the correct code back please.
% 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
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