Question

In: Computer Science

Create a Matlab program to load in the attached file File_Q5_Use.csv. You will first need to...

Create a Matlab program to load in the attached file File_Q5_Use.csv. You will first need to click on the link to open it, then save it as a .csv file in the directory you are using in your Matlab programs before you can load it in to Matlab.

It has 2 columns, the first column is the x values, the second column is the y values. Set Figure (1). Plot the points using red stars and a blue line with a title of 'Original Points' and get a general idea of what the degree of the polynomial is. It might be easier to split the matrix into 2 vectors x_vec and y_vec.

From the graph - where approximately are the real zeros of this polynomial? Does this polynomial appear to be ODD or EVEN. ? Answer the questions in the %RESULTS.  

After this plot, set Figure (2) to get a different Figure window open but so that the old figure window does not close.

Next, use POLYFIT to find the polynomial that fits the data [Hint: it is less than degree 8 and more than degree 1]. Use a FOR loop to cycle through the from n = 2:1:7 and do the following on each loop:

a. Find using POLYFIT, the polynomial for each degree of n. Do NOT suppress the values of the coefficients returned by each pass through the FOR loop.  

b. Using SUBPLOT where n is the location, plot on the same graph, the original points using red stars and the polynomial created by POLYFIT using a range of [-3:0.1:3] using a blue line. Make a title for each subgraph showing the degree of the polynomial fitted.  

Based upon the 6 graphs, which do you think is the correct degree of the polynomial? Answer in %RESULTS.

The basis for this polynomial was: 2x^5 - 3x^4 + 2x^3 -3x^2 - 144x + 216 = 0. Create a Figure 3 which plots the original points in red stars and points from this polynomial in a blue line for a range of [-3 : 0.1 : 3 ].  

Looking at the graphs, how many data points appear to be outliers, i.e. they probably should not be used in the graph? Answer in %RESULTS.

Looking at the graphs, the plots for degree 5, 6, 7 all appear to be almost the same. Switch to full screen to examine Figure 2. Remembering that the line of best fit passes through as many points as possible and minimizes the distances between the line and the points, can you determine by eye which degree of 5, 6, or 7 would be best?

Save as LastName_FirstName_Quiz_5_6_Q5

File to open. Hint: Make sure this file is in the same directory where you are saving LastName_FirstName_Quiz_5_6_Q5.

File_Q5_Use.csv

this is the file content

-3 -162
-2.9 -63
-2.8 23
-2.7 98
-2.6 161
-2.5 315
-2.4 258
-2.3 294
-2.2 324
-2.1 347
-2 364
-1.9 376
-1.8 385
-1.7 389
-1.6 389.5
-1.5 388
-1.4 384
-1.3 378
-1.2 370
-1.1 360
-1 350
-0.9 339
-0.8 326
-0.7 314
-0.6 299
-0.5 285
-0.4 273
-0.3 258
-0.2 245
-0.1 329
0 216
0.1 200
0.2 187
0.3 174
0.4 153
0.5 143
0.6 129
0.7 114
0.8 99
0.9 84
1 70
1.1 55
1.2 41
1.3 27
1.4 13
1.5 0
1.6 -13
1.7 -24
1.8 -35
1.9 -44
2 -52
2.1 -58
2.2 -61.5
2.3 -62
2.4 -59
2.5 -53
2.6 -43
2.7 -28
2.8 -7
2.9 20
3 54

Solutions

Expert Solution

(*Note: Please up-vote. If any doubt, please let me know in the comments)

Matlab Code:
data = csvread('File_Q5_Use.csv');
%dividing the data into x & y vectors
x_vec = data(:,1);
y_vec = data(:,2);
%set figure 1
figure(1)
%make first plot as per the required specifications
plot(x_vec,y_vec,'Marker','*','color','b','markerfacecolor','r','MarkerEdgeColor','r')
title('Original Points')
%set figure 2
figure(2)

for n=2:1:7
subplot(2,3,n-1)
p = polyfit(x_vec,y_vec,n)
x = -3:0.1:3
y = polyval(p,x)
plot(x,y)
hold on
%plotting original data using red stars
plot(x_vec,y_vec,'Marker','*','markerfacecolor','r','MarkerEdgeColor','r','linestyle','None')
s = sprintf("Degree= %d",n)
title(s)
end

figure(3)
x = -3:0.1:3
basis = 2*x.^5 - 3*x.^4 + 2*x.^3 -3*x.^2 - 144*x + 216
%plotting original data using red stars
plot(x_vec,y_vec,'Marker','*','markerfacecolor','r','MarkerEdgeColor','r','linestyle','None')
hold on
%plotting the given function in blue line
plot(x,basis,'color','b')

%RESULTS: Based on the 6 subplots, the polynomial seems to be degree 5 as the points are best aligned with the curve
%Based on figure 3, 2 points appear to be outliers

Output Screenshots:


Related Solutions

ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
This is a Matlab Question Create MATLAB PROGRAM that can solve First Order Linear Differential Equation...
This is a Matlab Question Create MATLAB PROGRAM that can solve First Order Linear Differential Equation ( 1 example contains condition and the other does not have condition). 1. ty′ + 2y = t^2 − t + 1, y(1)=12 The correct answer is y(t) = 1/4 t^2 − 1/3 t + 1/2 + 1/12t^2 2. (x-1) dy/dx + 2y = (x+1)^2 The correct answer is y = (x(x+1) / x-1 ) + C(x+1) / x-1 The correct answer is
You have an Excel file attached to this link. You are to first transpose the data...
You have an Excel file attached to this link. You are to first transpose the data so that, instead of being in the horizontal format, it will be converted to the vertical form. Then to run a Multiple Regression and see which of the independent variables are significant and whether the overall model is significant. You also should be able to comment on the goodness of the fit. All of these require that you have thoroughly watched the video lectures...
a) Create a program for the msp430FR6989 .You will use need to program it to be...
a) Create a program for the msp430FR6989 .You will use need to program it to be able to use a external pulse switch to start/stop the blinking of LED1, and a second pulse switch to control the blinking of LED2. b) Modify Program #1 (b) to blink the number of times on the data switches once the pulse switch is engaged
Need to create a program in C++ that can display/write into a file called marks.txt. I'm...
Need to create a program in C++ that can display/write into a file called marks.txt. I'm not too worried about the functions, but I don't know how to store the different marks into a arrays. Any help would be appreaciated. Here's some details about the assignment. Student marks are kept in a text file as a single column. Each student may have a different number of assessments and therefore scores. The data recorded in the file for each student start...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
Create a Matlab program that can evaluate Green Theorem
Create a Matlab program that can evaluate Green Theorem
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT