50 50 40 40 Petrol Best Fit Weighted CO2 Emmisions Diesel Petrol Diesel Best Fit 30 50 о ° 8 о 20 20 о 0 0 CO2 Weighted Percentage 10 0 о -10 0 10 20 30 50 60 50 40 40 Car Position Diesel Best Fit Petrol Best Fit Weighted CO2 Emissions 35 30 25 CO2 Weighted Percentage 20 о Petrol Diesel о 15 10 20 % 30 8 о 8 о 35 30 Weighted CO2 Emissions Diesel Best Fit Petrol Best Fit Petrol Diesel 25 CO2 Weighted Percentage 8 оо о 200 о 15 40 50 60 10 Car Position 00 оо 40 50 60 20 20 30 Car Position 40

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
icon
Related questions
Question
This code keeps on generating graphs with different curves. The picture that you see two different graphs comes from the same code but both of them have different curves. I need the curve to look like the picture that only has one graph. I basically need the line to have a slight curve and every time I run the code it will come up as the same graph every time. Use this code on MATLAB and fix 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;
50
50
40
40
Petrol Best Fit
Weighted CO2 Emmisions
Diesel
Petrol
Diesel Best Fit
30
50
о
° 8
о
20
20
о
0 0
CO2 Weighted Percentage
10
0
о
-10
0
10
20
30
50
60
50
40
40
Car Position
Transcribed Image Text:50 50 40 40 Petrol Best Fit Weighted CO2 Emmisions Diesel Petrol Diesel Best Fit 30 50 о ° 8 о 20 20 о 0 0 CO2 Weighted Percentage 10 0 о -10 0 10 20 30 50 60 50 40 40 Car Position
Diesel Best Fit
Petrol Best Fit
Weighted CO2 Emissions
35
30
25
CO2 Weighted Percentage
20
о
Petrol
Diesel
о
15
10
20
%
30
8
о
8
о
35
30
Weighted CO2 Emissions
Diesel Best Fit
Petrol Best Fit
Petrol
Diesel
25
CO2 Weighted Percentage
8
оо
о
200
о
15
40
50
60
10
Car Position
00
оо
40
50
60
20
20
30
Car Position
40
Transcribed Image Text:Diesel Best Fit Petrol Best Fit Weighted CO2 Emissions 35 30 25 CO2 Weighted Percentage 20 о Petrol Diesel о 15 10 20 % 30 8 о 8 о 35 30 Weighted CO2 Emissions Diesel Best Fit Petrol Best Fit Petrol Diesel 25 CO2 Weighted Percentage 8 оо о 200 о 15 40 50 60 10 Car Position 00 оо 40 50 60 20 20 30 Car Position 40
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Elements Of Electromagnetics
Elements Of Electromagnetics
Mechanical Engineering
ISBN:
9780190698614
Author:
Sadiku, Matthew N. O.
Publisher:
Oxford University Press
Mechanics of Materials (10th Edition)
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:
9780134319650
Author:
Russell C. Hibbeler
Publisher:
PEARSON
Thermodynamics: An Engineering Approach
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:
9781259822674
Author:
Yunus A. Cengel Dr., Michael A. Boles
Publisher:
McGraw-Hill Education
Control Systems Engineering
Control Systems Engineering
Mechanical Engineering
ISBN:
9781118170519
Author:
Norman S. Nise
Publisher:
WILEY
Mechanics of Materials (MindTap Course List)
Mechanics of Materials (MindTap Course List)
Mechanical Engineering
ISBN:
9781337093347
Author:
Barry J. Goodno, James M. Gere
Publisher:
Cengage Learning
Engineering Mechanics: Statics
Engineering Mechanics: Statics
Mechanical Engineering
ISBN:
9781118807330
Author:
James L. Meriam, L. G. Kraige, J. N. Bolton
Publisher:
WILEY