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

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:

i hope it helps..

If you have any doubts please comment and please don't dislike.

PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME


Related Solutions

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...
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
2. Create a java program that reads a file line by line and extract the first...
2. Create a java program that reads a file line by line and extract the first word.        The program will ask for the name of input and output file. Input file: words.txt today tomorrow sam peterson peter small roy pratt Output file: outwords.txt tomorrow peterson small pratt
IN C LANGUAGE ONLY PLEASE! First Program: create branchloop.c file Content of the program Enter your...
IN C LANGUAGE ONLY PLEASE! First Program: create branchloop.c file Content of the program Enter your name while running your program as you did with hello2.c (using argc and argv) name has to be 2 words max (e.g. Jose Lopez, Maria Rodrigues) . Make sure to check properly. Print your name 10 times using a loop. 10 is a fixed number. Count how many characters are in your first name and last name. If the number of characters of your...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT