Question

os Time 2 4 6 7 Voltage 1.1 1.9 3.3 3.4 3.1 3.3 7.1 Fit a straight line through the data points, and then plot this line along with the sample voltages According to your straight line, determine at what time the voltage would be 5Please solve it with matlab

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

% Matlab script to fit a straight line through a given set of points and
% plot the points and the line and find the voltage for time=5 from that
% plot
% define the variables to hold the time and voltage data
t = [1,2,3,4,5,6,7];
v = [1.1,1.9,3.3,3.4,3.1,3.3,7.1];
% finds the coefficients of a polynomial P(t) of
% degree 1 that fits the data Y best in a least-squares sense.
p = polyfit(t,v,1); % returns the coefficients for a polynomial,p , of degree 1 that is a best fit for the data in v
% returns the value of a polynomial P evaluated at t.
f = polyval(p,t);
% returns the value of the polynomial evaluated at t=5
f_5 = polyval(p,5);
fprintf(' Value of polynomial at t=5 : %f\n',f_5);
plot(t,v,'o',t,f,'-');
xlabel('Time');
ylabel('Voltage');
title('Plot of Voltage vs Time');
grid on;

%end of script

Output:

value of polynomial at t=5 : 4.050000 Figure 1 Plot of Voltage vs Time 6 5 7 4 3 2 4 Time 2 7

Add a comment
Know the answer?
Add Answer to:
Please solve it with matlab os Time 2 4 6 7 Voltage 1.1 1.9 3.3 3.4...
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