Question

In: Computer Science

%Purpose: %Fit a first degree polynomial, %a second-degree polynomial, %and a third-degree polynomial to these data...

%Purpose:
%Fit a first degree polynomial,
%a second-degree polynomial,
%and a third-degree polynomial to these data
%Plot all three plots (along with the original data points)
%together on the same plot and determine the BEST fit
%After determining the best fit add additional code to the end of your script
%to predict the pressure at t = 11 seconds from the best-fitting curve
%INPUT VARIABLES:
t = 1:0.05:10;
p = [26.1,27,28.2,29,29.8,30.6,31.1,31.3,31,30.5];
d1 = polyfit( t, p, 1 ); %first degree
d2 = polyfit( t, p, 2 ); %second degree
d3 = polyfit( t, p, 3 ); %third degree
t1 = 1:0.05:10;
p1 = polyval(d1,t1);
p2 = polyval(d2,t1);
p3 = polyval(d3,t1);
%
%OUTPUT VARIABLES:
%plot(t,p,'o') original data points
%plot(t, p1,)first degree
%plot(t, p2,)second degree
%plot(t, p3, '--')third degree
%title ('Fuel Line Pressure Predictions');
%xlabel('Time (sec)');
%ylabel('Pressure (psi)');
%
%OUTPUT SECTION:
plot(t,p,'o')
plot(t1,p1);
plot(t1,p2);
plot(t1,p3,'--');
title ('Fuel Line Pressure Predictions')
xlabel('Time (sec)')
ylabel('Pressure (psi)')

I am not sure what is wrong with my code. The errors that pop up are:

Error using polyfit (line 44)
The first two inputs must have the same number of elements.

Error in EngrProb_1 (line 17)
d1 = polyfit( t, p, 1 ); %first degree

Solutions

Expert Solution

Third degree is the best fit

code :

output :

raw_code :

%Purpose:
%Fit a first degree polynomial,
%a second-degree polynomial,
%and a third-degree polynomial to these data
%Plot all three plots (along with the original data points)
%together on the same plot and determine the BEST fit
%After determining the best fit add additional code to the end of your script
%to predict the pressure at t = 11 seconds from the best-fitting curve
%INPUT VARIABLES:
t = 1:1:10;
p = [26.1,27,28.2,29,29.8,30.6,31.1,31.3,31,30.5];
d1 = polyfit( t, p, 1 ); %first degree
d2 = polyfit( t, p, 2 ); %second degree
d3 = polyfit( t, p, 3 ); %third degree

p1 = polyval(d1,t);
p2 = polyval(d2,t);
p3 = polyval(d3,t);

figure
hold on
plot(t,p,'o') %plotting original points
plot(t,p1);
plot(t,p2);
plot(t,p3,'--');
title ('Fuel Line Pressure Predictions')
xlabel('Time (sec)')
ylabel('Pressure (psi)')

%third degree is best fit
%predicting pressure value at t =11
predict = polyval(d3,11);
fprintf('pressure at t = 11 is %f\n',predict)

**do comment for queries and rate me up****


Related Solutions

Provide an example of price discrimination and classify it as first-degree, second-degree or third-degree price discrimination.
Provide an example of price discrimination and classify it as first-degree, second-degree or third-degree price discrimination.
Provide an example of price discrimination and classify it as first-degree, second-degree or third-degree price discrimination
Provide an example of price discrimination and classify it as first-degree, second-degree or third-degree price discrimination
Match the corresponding examples of first-degree, second-degree, or third-degree price discrimination. 1. The publishers of the...
Match the corresponding examples of first-degree, second-degree, or third-degree price discrimination. 1. The publishers of the Journal of Price Discrimination charge a subscription price of $75 per year to individuals and $300 per year to libraries. 2. Ye Olde Country Club charges golfers $12 to play the first 9 holes of golf on a given day, $9 to play an additional 9 holes, and $6 to play 9 more holes. 3. The U.S. government auctions off leases on tracts of...
QUESTION 5 In the diagnosis, "first, second, and third degree burns of the chest wall," a...
QUESTION 5 In the diagnosis, "first, second, and third degree burns of the chest wall," a code is required for: A. Each of the 1st, 2nd, and 3rd degree burns B. The 1st degree burn only C. The 3rd degree burn only D. The 2nd degree burn only 10 points    QUESTION 6 When coding for full-thickness free skin grafts, which of the following is not an essential item of data needed for accurate coding? A. Type of graft (full-thickness,...
4. Define first degree price discrimination, second degree price discrimination, and third degree price discrimination. Provide...
4. Define first degree price discrimination, second degree price discrimination, and third degree price discrimination. Provide an example of each.
Compare the tissue involvement in first-degree, second-degree full-thickness, and third-degree burns. Describe burns based on depth...
Compare the tissue involvement in first-degree, second-degree full-thickness, and third-degree burns. Describe burns based on depth of injury. Discuss burn classification. Describe estimation of total body surface area (TBSA) in a burn. Explain the rule of nines as a method of determining the extent of a burn
Please answer First, Second and third degree price discrimination with business world examples
Please answer First, Second and third degree price discrimination with business world examples
Task 3: a) A second-degree polynomial in x is given by the expression = + +...
Task 3: a) A second-degree polynomial in x is given by the expression = + + , where a, b, and c are known numbers and a is not equal to 0. Write a C function named polyTwo (a,b,c,x) that computes and returns the value of a second-degree polynomial for any passed values of a, b, c, and x. b) Include the function written in part a in a working program. Make sure your function is called from main() and...
What is second degree price discrimination and third degree price discrimination? Explain with examples.
What is second degree price discrimination and third degree price discrimination? Explain with examples.
Find a third-degree-polynomial model of salinity  as a function of time . Use the general form of...
Find a third-degree-polynomial model of salinity  as a function of time . Use the general form of a polynomial in the box on page 114 of our textbook. Hint: proceed much as you did for the quadratic model, and look ahead to the next paragraph. Explain why it’s possible to find more than one third-degree-polynomial model that fits the data perfectly. Use your third-degree-polynomial model to predict the salinity at . Make a large graph of your third-degree-polynomial model, at least...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT