Answered step by step
Verified Expert Solution
Question
1 Approved Answer
provide a matlab code for this :Regression and Interpolation In this exercise, we are going to use MATLAB's built - in functions for regression and
provide a matlab code for this :Regression and Interpolation In this exercise, we are going to use MATLAB's builtin functions for regression and interpolation. The goal is to determine whether regression or interpolation is the better choice for a given set of data. We are going to revisit two sets of data that you previously used. clear; clc; Upload the data to the MATLAB workspace. Assign the time column to the variable and the current column tot he variable Plot this data using black circles as markers. Add figure titles and axes labels. A importdatacurrenttxt tc Adata:; ic Adata:; figure; plottc icko; titleCURRENT VS TIME", "fontsize", xlabelTIME s"fontsize", ylabelCURRENT A "fontsize", p polyfittc ic Iinterpolated interptc ic tc grid on Upload the data to the MATLAB workspace. Assign the time column from seconds to seconds to the variable and the corresponding current column to the variable This time range corresponds to the index to Plot this data using black circles and solid lines as markers. Add figure titles and axes labels. Bimportdatanormaltxt timerange tc & tc; selectedtimes tctimerange tn tctimerange fn ictimerange plottc icok 'MarkerFaceColor', 'black', 'MarkerSize', ; titleCURRENT VS TIME", "fontsize", xlabelTIME s"fontsize", ylabelCURRENT A "fontsize", grid on TASK Peform Regression on Data Sets For both data sets, perform polynomial regression. To do this, use the function. The first two arguments are the x and ydata set. The third argument is the order of the polynomial. Thus, if we're talking about linear regression, then the third argument should be For now, we let the order be equal to Assign the order to the variable in the field below. currentdata importdatacurrenttxt; xcurrent currentdata.data:; ycurrent currentdata.data:; Perform linear regression on the current dataset ordercurrent ; We are now going to record the process time for the regression algorithm. This command begins the time recording. tic DO NOT CHANGE THIS COMMAND LINE. The output of the function will be the coefficients of the polynomial equation, the first being the slope of the best fit line, while the second is the yintercept. The polynomial function is given by where is the fitting function and are the coefficients of generated from the function. Use the function to determine the coefficients of the and data. Assign the output to the variables and respectively. Remember to use the variable as the third argument. DO NOT PUT SEMICOLONS so that you can see the output values. coefficientscurrent polyfitxcurrent, ycurrent, ordercurrent; This command stops the time recording. toc DO NOT CHANGE THIS COMMAND LINE. Record the elapse time in the table below. Using the xdata set for current, generate a new set of current values from the coefficients obtained from the Assign these new data set to the variable yfitcurrent polyvalcoefficientscurrent, xcurrent; Plot the best fit line, and compare it in the same plot with the original current data, Use the same black circles for the current data and a red line, with a LineWidth of units, for the best fit line. plotxcurrent, ycurrent, ok 'MarkerFaceColor', 'black'; hold on; plotxcurrent, yfitcurrent, r 'LineWidth', ; hold off; titleCURRENT VS TIME', 'fontsize', ; xlabelTIME s 'fontsize', ; ylabelCURRENT A 'fontsize', ; legendOriginal Data', 'Best Fit Line'; ncurrent numelxcurrent; errorcurrent sumycurrent yfitcurrent ncurrent; Display results dispResults for Current Dataset:; dispCoefficients: numstrcoefficientscurrent; dispElapsed Time: numstrelapsedtimecurrent seconds'; dispError: numstrerrorcurrent; Using the xdata set for current, generate a new set of current values from the coefficients obtained from the Assign these new data set to the variable normaldata importdatanormaltxt; timerange tc & tc; selectedtimes tctimerange tn tctimerange fn ictimerange ordernormal ; Plot the best fit line, and compare it in the same plot with the original current data, Use the same black circles and solid lines for the current data and a red line, with a LineWidth of units, for the best fit line. coefficientsnormal polyfitxnormal, ynormal, ordernormal; The equation for the error is shown in one of the video lectures and is given by where is the number of data points and is the highest power or degree of the polynomial fitting function, Solve for the error corresponding to each fit. Use the function to make it easier for you to sum matrix elements. Assign the variables and to th
provide a matlab code for this :Regression and Interpolation
In this exercise, we are going to use MATLAB's builtin functions for regression and interpolation. The goal is to determine whether regression or interpolation is the better choice for a given set of data. We are going to revisit two sets of data that you previously used.
clear; clc;
Upload the data to the MATLAB workspace. Assign the time column to the variable and the current column tot he variable Plot this data using black circles as markers. Add figure titles and axes labels.
A importdatacurrenttxt
tc Adata:;
ic Adata:;
figure;
plottc icko;
titleCURRENT VS TIME", "fontsize",
xlabelTIME s"fontsize",
ylabelCURRENT A "fontsize",
p polyfittc ic
Iinterpolated interptc ic tc
grid on
Upload the data to the MATLAB workspace. Assign the time column from seconds to seconds to the variable and the corresponding current column to the variable This time range corresponds to the index to Plot this data using black circles and solid lines as markers. Add figure titles and axes labels.
Bimportdatanormaltxt
timerange tc & tc;
selectedtimes tctimerange
tn tctimerange
fn ictimerange
plottc icok 'MarkerFaceColor', 'black', 'MarkerSize', ;
titleCURRENT VS TIME", "fontsize",
xlabelTIME s"fontsize",
ylabelCURRENT A "fontsize",
grid on
TASK Peform Regression on Data Sets
For both data sets, perform polynomial regression. To do this, use the function. The first two arguments are the x and ydata set. The third argument is the order of the polynomial. Thus, if we're talking about linear regression, then the third argument should be For now, we let the order be equal to Assign the order to the variable in the field below.
currentdata importdatacurrenttxt;
xcurrent currentdata.data:;
ycurrent currentdata.data:;
Perform linear regression on the current dataset
ordercurrent ;
We are now going to record the process time for the regression algorithm. This command begins the time recording.
tic DO NOT CHANGE THIS COMMAND LINE.
The output of the function will be the coefficients of the polynomial equation, the first being the slope of the best fit line, while the second is the yintercept. The polynomial function is given by
where is the fitting function and are the coefficients of generated from the function.
Use the function to determine the coefficients of the and data. Assign the output to the variables and respectively. Remember to use the variable as the third argument. DO NOT PUT SEMICOLONS so that you can see the output values.
coefficientscurrent polyfitxcurrent, ycurrent, ordercurrent;
This command stops the time recording.
toc DO NOT CHANGE THIS COMMAND LINE. Record the elapse time in the table below.
Using the xdata set for current, generate a new set of current values from the coefficients obtained from the Assign these new data set to the variable
yfitcurrent polyvalcoefficientscurrent, xcurrent;
Plot the best fit line, and compare it in the same plot with the original current data, Use the same black circles for the current data and a red line, with a LineWidth of units, for the best fit line.
plotxcurrent, ycurrent, ok 'MarkerFaceColor', 'black';
hold on;
plotxcurrent, yfitcurrent, r 'LineWidth', ;
hold off;
titleCURRENT VS TIME', 'fontsize', ;
xlabelTIME s 'fontsize', ;
ylabelCURRENT A 'fontsize', ;
legendOriginal Data', 'Best Fit Line';
ncurrent numelxcurrent;
errorcurrent sumycurrent yfitcurrent ncurrent;
Display results
dispResults for Current Dataset:;
dispCoefficients: numstrcoefficientscurrent;
dispElapsed Time: numstrelapsedtimecurrent seconds';
dispError: numstrerrorcurrent;
Using the xdata set for current, generate a new set of current values from the coefficients obtained from the Assign these new data set to the variable
normaldata importdatanormaltxt;
timerange tc & tc;
selectedtimes tctimerange
tn tctimerange
fn ictimerange
ordernormal ;
Plot the best fit line, and compare it in the same plot with the original current data, Use the same black circles and solid lines for the current data and a red line, with a LineWidth of units, for the best fit line.
coefficientsnormal polyfitxnormal, ynormal, ordernormal;
The equation for the error is shown in one of the video lectures and is given by
where is the number of data points and is the highest power or degree of the polynomial fitting function,
Solve for the error corresponding to each fit. Use the function to make it easier for you to sum matrix elements. Assign the variables and to th
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started