Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

this is being coded in matlab, having trouble with finding the error equations 2. Curve-Fitting Program Recently, acoustic Doppler current profilers (ADCP) allow for the

this is being coded in matlab, having trouble with finding the error equations

2. Curve-Fitting Program Recently, acoustic Doppler current profilers (ADCP) allow for the river flow velocity to be measured instantaneously along a cross-section of a river. In this assignment, we will be using 3 data for a side-looking ADCP that is permanently mounted at a river gauging station. Thus, we are able to generate a large dataset of discharge versus gauge height. The data are reported in cubic feet per second (cfs) for discharge and in feet (ft) for gauge height, and the gauge height in the dataset represents the height above the zero-flow height; hence, h0 in Equation (1) is zero.

First, we must obtain the stage-discharge data and store them on our hard drive for analysis. Download the function file gaugedata.m from the course website. At the Matlab prompt, run the commands [Q, h, a2, b2] = gaugedata; data = [h Q]; save my_data.dat -ascii data a2 b2 The first line generates a random set of data for you to analyze. The second line, packs these data in a single variable so that the first column contains stage in ft and the second column contains discharge in cfs. The third line saves this data in a file called my_data.dat. The fourth and fifth lines display the values stored in the fit parameters a2 and b2. Write down these parameter values for comparison later to your curve fit. Write a Matlab program to do the following tasks. For the curve fitting, you should write your own function file. You may base this file on Figure 14.15 in the Chapra (2011) textbook.

Load in the data and plot the data as points . (blue dot) in figure(1).

Fit a power law of the form 2 2 b Q ah = (2) and report the fitted parameter values a2 and b2. Compare these values to the base values output in the commands above. Overlay the data in figure(1) with the fitted curve.

Create a scatter plot in a second figure window that presents the actual error Q Q n = - and the squared error ( ) 2 2 Q Q n = - for each measurement. On the x-axis, plot the measured gauge height h, and on the y-axis plot the errors. Use the subplot(2,1,1) command to plot the n errors and subplot(2,1,2) command to plot the 2 n errors. Experiment with linear, log, and loglog plots to get the best presentation of the data. Remember to label your axes including units of the data.

Calculate the mean and standard deviation of the errors Q Q n = - and squared errors ( ) 2 2 Q Q n = - . Report these calculated values with their appropriate units. Remove the data points from the dataset that correspond to the top 3 errors Q Q n = - . You should write the code in your program to do this automatically. Repeat the curve fit 4 for this new data set, output the new fit coefficients, and compute the mean and standard deviation of the n and 2 n errors. How has the fit improved or gotten worse in comparison to the base answer recorded above?

Plot the revised curve fit in figure(1) with the other data and curves. Make the revised curve thicker by setting LineWidth equal to 2.5 in plot so the revised curve stands out. Also plot an x (red cross) on top of the data points that were removed. Add a legend to the plot and be sure to label your axes. Comment on any improvement you observe in the fit and explain how the fit has changed. You may use the built-in Matlab functions min, max, mean, and std, but do not use any other Matlab functions that replace significant parts of the programming work, such as find, polyfit, or nlinfit.

here is the guage data function:

function [Q, h, a2, b2] = gaugedata % % GAGEDATA Generate synthetic stage-discharge measurements % % This function uses random number generators to generate synthetic % measurements of discharge Q in cfs versus gauge height (called river % stage) h in ft. The gauge height is normalized so that zero flow rate is % obtained at zero gauge height. % % Example % [Q, h, a2, b2] = gaugedata; % % Kuang-An Chang % Modified from Prof. Socolofsky's lecture % CVEN 302 % Spring 2014

% The base stage-discharge relationship is obtained from the Brazos River % at State Highway 21 near Bryan, and it approximated by Q = 190 x ^(1.64). % Enter the base parameters of the fit a0 = 1.64; a1 = 190; % Generate a random set of parameters a0 = a0 + 2*sqrt(3)*rand(1) * 0.6; a1 = a1 + randn(1) * 85; % Generate the synthetic data hmax = 45; hmin = 0.5; nh = 5; dh = (hmax - hmin) / (nh - 1); xp = 0.5; for i = 1:nh xp = [xp hmin+dh*i/5:dh*i/20:dh*i]; end xp = xp' + 0.05*randn(length(xp),1).*xp'; yp = (a1 + randn(length(xp),1)*a1*0.03) .* xp .^ ... (a0 + randn(length(xp),1)*a0*0.03); h = xp; Q = yp;

% Get some data at high flow rate n_errors = 3; he = linspace(40,60,n_errors); he = he' + 0.05*randn(length(he),1).*he'; Qe = (a1 + randn(length(he),1)*a1*0.03) .* he .^ ... (a0 + randn(length(he),1)*a0*0.03);

% Randomly insert the high flow-rate data and add a systematic error to it. for i = 1:n_errors j = floor(rand*length(h)); Q(j) = Qe(i) - 0.3*2*sqrt(3)*rand(1).*Qe(i); h(j) = he(i); end

% Remove any negative values h(h<0) = -h(h<0); Q(Q<0) = -Q(Q<0); a2 = a1; b2 = a0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students explore these related Databases questions