Homework 5 Engineering 0012 Spring 2017 Due Tuesday January

Homework #5 Engineering 0012 Spring 2017 Due: Tuesday, January 31, 2017 Your task is to write a MATLAB script that will plot a set of data and fit a curve to the data. The script should: Part 1 1. Have a section that allows the user to enter the name of a data file Be capable of reading data stored in either rows or columns. 3. Allow the user to select the color and type of plot symbol 4. Once the data is entered, it should plot the x y data. Enter a pause in the program so the user can view the output of the plot, then fit the data with a linear line. Do not use the polyfit command to find the coefficients of the equation. Instead use linear algebra to solve the equations for the best fit shown in the text book. 6. Allow the user to select the color of the line, and plot the x data and best fit line on the same graph. 7. Calculate the absolute error and relative error. Have the script display the maximum value of both errors and the x coordinate corresponding to each maximum error. e careful with dividing by zero. What do you do? 8. Calculate the r-squared value 9. Add the equation of the line and the r-squared value to the graph (for now enter the words r-squared, will show you how to enter r later 10. Have a section that will allow the user to enter the plot title, and x and yaxis labels 11 Allow the user to estimate the value of the best fit for any x coordinate 12. Once the user is satisfied with the results, the script should allow the user to enter a new set of data without ending the program. Do not use a menu for this. Make sure the script allows for user input emor (e. Check for words versus characters and for incorrect characters) 13. Once you have completed this, enter the same data sets into Excel and fit a trend line to the data. Do you get the same equations and r-squared value? What software would you use it given this task to do for another class? Part 2 14. Once the script is complete, modify it so the user has the option to fit a linear line or a polynomial Use an if statement to select the choice 15. For the polynomial fit use polyfit, the program should use at least 300 data points to plot the curve and the program should be capable of starting the curve at the smallest and largest x coordinate without user input. 16. Once the polymomial is fit to the data the program should allow the user to try different degree fits to the data. Make sure you check for the maximm degree. 17. Add the equation to the plot, along with titles and labels. Note, adding the equation to the plot requires you to build a string array Procedure: Given below is a table containing two sets of data. Data set 1 would be the x colum and the data set 1 column. Data set 2 would be the x column and data set 2 column.) Enter these data into two separate data files. Data set 1 should be entered as rows and named rowdata.dat. Data set 2 should be entered as columns and named colsdata-dat. Then prepare individual plots of these data with the best fit curves and save the plots as figurel fig and figure2.fig. Be sure to give each plot a title, x & y-axis labels and a legend y values y values data data setl 1.4 10.0 0.5 1.3 5.0 1.0 1.1 3.0 1.5 0.9 6.0 2.0 0.7 10.4 3.0 0.4 4.0 0.27

Solution

%% Init variables

xlist = 0:0.1:360; % range of x values

ymax = 0;

ymaxloc = 0;

%% Loop for calculations

for i=1:length(xlist)

    x = xlist(i); % current value of x just to make the equations easier to read

    % calc deflection in several steps

    y = 800*x^3 - 13.68e6*x - 2.5*x^4;

    if x>=120

        y = y + 2.5*(x-120)^4;

    end

    if x>=240

        y = y + 600*(x-240)^3;

    end

    y = y / 3.19e9;

    ylist(i) = y; % save in list

    % check to see if this is the max deflection and save if it is

    if abs(y)>abs(ymax)

        ymax = y;

        ymaxloc = x;

    end

end

%% Plot results

plot(xlist,ylist,\'b-\');

hold on;

plot(ymaxloc,ymax,\'r*\');

text(ymaxloc,ymax,sprintf(\'Max deflection=%.4f at %.1f\',ymax,ymaxloc));

xlabel(\'Distance along beam (inches)\')

ylabel(\'Beam deflection (inches)\')

title(\'Beam deflection using discontinuity functions\');

 Homework #5 Engineering 0012 Spring 2017 Due: Tuesday, January 31, 2017 Your task is to write a MATLAB script that will plot a set of data and fit a curve to t
 Homework #5 Engineering 0012 Spring 2017 Due: Tuesday, January 31, 2017 Your task is to write a MATLAB script that will plot a set of data and fit a curve to t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site