Question

of motor vehicles 2. The table displays the mass M and average fuel consumption manufactured by Ford and Honda. Using the lea

USE MATLAB FOR ALL ANSWERS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Using the least square fit for linear regression, the required straight line fit for the given data is obtained using MATLAB. The required mass vs fuel consumption graph is also plotted and the standard deviation is computed as well. All the results are attached below: (MATLAB codes are also attached)Command Wind ow >>M-[1310 1810 1175 2360 1960 2020 1755 1595 1470 1430 1110 1785]; >>phi = [10.2 8.1 11.9 5.5 6.8 6.8 7.7 8.9Mass vs Fuel consumption Regression line Data using regression line Actual data 13 12 11 7 6 5 4 2000 2500 1000 1500 Mass(kg)

MATLAB code:

function linear_fit(phi,M)

M1=sum(M);
M2=sum(M.^2);
phi1=sum(phi);
phi1M1=sum(phi.*M);
n=numel(M);
A=[n M1;M1 M2];
b=[phi1;phi1M1];
ab=A\b;
fprintf('\nRequired straight line fit is: phi=(%g)+(%g) M\n\n',ab(1),ab(2));
  
f=@(ab,M) ab(1)+ab(2)*M;
x=min(M)-100:1:max(M)+100;
y=f(ab,x);
y1=f(ab,M);
y2=(y1-phi).^2;
SD=sqrt(sum(y2)/n);
fprintf('\nRequired standard deviation of the fit is: %g\n\n',SD);
plot(x,y,M,y1,'o',M,phi,'*');
xlabel('Mass(kg)')
ylabel('Fuel consumption(km/litre)')
legend('Regression line','Data using regression line','Actual data')
title('Mass vs Fuel consumption')
AA=[M' y1'];
VarNames = {'Mass','Fuel_consumption_from_regression_line'};
TT=table(AA(:,1),AA(:,2), 'VariableNames',VarNames);
disp(TT);
end

Add a comment
Know the answer?
Add Answer to:
USE MATLAB FOR ALL ANSWERS of motor vehicles 2. The table displays the mass M and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT