Parse and load data files and deal with missing data

Assignment Help MATLAB Programming
Reference no: EM131110985

1 Goals

To write code to

- parse and load data files and deal with missing data,
- implement a more complex program involving multiple function calls.
- output nicely formatted results and figures summarizing your analyses.


2 Background - the theory governing the electrical condutivity of natural waters

Certain basic properties of lakes and oceans are important to understanding how they "work". These include tem- perature (i.e., the heat content), and the amount of dissolved matter (the salt content). One measure of the dissolved matter is the VOLUMETRIC SALINITY S, which is the total amount of dissolved stuff measured in units of grams per liter of solution. Seawater has salinities of 2-35 g/l, but even fresh water in lakes (and our drinking water) has small amounts of dissolved material (typically .1-1 g/l in most lakes, but sometimes up to 70 g/l or more in so-called
saline lakes, which usually are in hot dry places with a lot of evaporation)∗.

Temperature is pretty easy to measure, but the salinity is not. In general, the dissolved matter consists of a large number of different ions, each of which may require specialized chemical analysis techniques to measure properly. However, we can get a rough idea of the concentration of charged ions in solution by measuring the electrical
conductivity of the water at a fixed reference temperature (usually chosen to be 25?C). This is a relatively easy thing
to measure. The salinity in g/l and conductivity κ in mS/cm ("milli-Siemens per cm") are related by a factor α such that
S = ακ (1)
where this factor α is specific to a particular lake (i.e., a particular ionic composition), but is usually around 0.5-1. In this lab we are going to write to code to try and predict the α ratio a bit more accurately for lakes with a known chemical composition.

Conductivity is related to the speed at which electrical charges (attached to ions) move through the fluid (the "elec- trical current") when a voltage is applied. The total current is the combined effect of the current that arises from the effects of each ion. Let us assign each type of ion to an index i = 1 . . . N . Since different ions have differ- ent sizes, masses, and electrical charges they each have their own INFINITE DILUTION IONIC EQUIVALENT† CONDUCTIVITY λo. Then the total measured conductivity κ would be the sum of these:

where zi is the charge on the ion and ci is its concentration in MOLES PER LITER SOLUTION. For example,zi = 1 for Na+ (sodium), and zi = -2 for SO2- (sulfate). Note that the volumetric salinity can also be calculated

where Mi is the MOLAR MASS of the different ions (see Table 1), and ci is again the concentration.However, when there are lots of other ions around, their electric fields can "screen" each other, so that the actual ∗Since volume changes with temperature, assume that we are dealing with volume at a reference temperature of 25?C in this assignment. † In this context, the word EQUIVALENT means that the value is per charge, rather than per 


1694_1.png

(Note - equation (5) is actually good only for pretty weak ionic concentrations. At higher salinities the dependence on I becomes more complicated, and other effects in addition to this 'screening' also become important in many natural waters, but we are going to ignore that here).

Although natural waters (i.e. lake, river, and seawaters) contain almost everything at some concentration, most of the dissolved material is composed of 7 different ions, the so-called MAJOR IONS. These are listed in Table 1, along with their molar masses, charges, and the parameters for calculating their equivalent conductivities.

One final issue is that ions are not present in arbitrary amounts. Since you don't get electrocuted when you touch water (!), the number of positive charges must EXACTLY equal the number of negative charges. That is, the CHARGE BALANCMUST equal zero (exactly) for any water containing ions. One advantage of this is that if you have a measurement that doesn't include one of the major ions (typically bicarbonate, or HCO-), you can estimate this by adding up the charges of the other ions and then setting the concentration of HCO- to balance the excess of positive charge.
Another advantage is that you can calculate the charge balance as a check value on the data, to see if it makes sense (or whether an error has crept into the values).


3 The assignment - an overview

The assignment is basically concerned with the writing of a number of functions which can implement the conduc- tivity theory described above. These functions will then be called by a program which will load data files containing the composition of a number of natural waters and make some plots comparing them. The organization of the functions is up to you, but one way of doing this is to have


• assign2.m containing the "driver" code which reads water composition data and makes plots
• cond.m containing the function cond, and subfunction istrength. This will compute the conductivity for a given chemical composition, with the subfunctions computing the ionic strength of the solution.
• chargebal.m containing the function chargebal which will compute the charge balance for a given composition.
• salinity.m containing the function salinity which will compute the salinity of a given composition.
• loadcomp.m containing the function loadcomp which will load data in a given filename, and return a row vector containing the composition.

Some other hints are:

• Since there are 7 different ions, you could use a different variable name for each in your code. However, it is more efficient to store their data in row vectors, where each column represents data for a particular ion.
• Avoid "hard-wiring" numbers into your code. Keep the (fixed) data for molar masses, ionic charges, and so on in row vectors specified ONCE. This makes it much easier to modify your program to take into account changes in the molar masses, number of ions in the compositions, or other factors.
• The simplest starting point is to write code that can load in a composition, and compute its salinity and charge balance. Missing data in composition files is specified by a -999 value. Salinities of compositions with missing data should return an error. Charge balance calculations should ignore missing data (i.e. make the calculation assuming a value of zero for the missing data).
• Above all, resist the tendency to start writing code BEFORE you REALLY understand WHAT you have to code. IN PARTICULAR, use pencil and paper to specify the INPUTS and OUTPUTs of all functions, and specify WHERE (in what functions) the different kinds of information in Table 1 is required.


4 The assignment itself

1. Read ALL the background, and ALL parts of the asignment (I wasn't kidding in the hints).
2. Begin with seawater. Load the seawater composition seawater.txt, and compute its salinity (check value 35.12978962193 g/l, perhaps varying in the last decimal place depending on details of the computation) and conductivity (check value 46.86864157996 mS/cm). The composition of seawater at other salinities can be found by scaling the ionic concentrations by a constant factor. For example, IF the salinity was 40 (it is not), then you could find concentrations for a salinity of 10 by scaling with a factor of 10/40.
• PLOT: the conductivity (on y axis) for salinities of 0.1 to 35 g/l (on x axis).Take enough steps between
0.1 and 25 so that the curve LOOKS SMOOTH when plotted.
• PLOT: the factor α (on y axis) for salinities of 0.1 to 35 g/l (on x axis). Make both of these plots as subplots, one above the other, with the x axes aligned.
3. Seawater is mostly made up of sodium and chloride (i.e. table salt). If you take a solution of ONLY Na+ and
Cl- (i.e. with the amounts of all other ions set to zero), what is α for salinities of 0.1 to 35?
• PLOT: Add the conductivity and α curves to the two from the previous section.
• TEXT: How much of a difference does approximating seawater with a sodium chloride solution make in the conductivity at a salinity of 10 g/l (i.e. what is the percent error)?

4. Read in the compositions of world average freshwater (worldriver.txt), Mahoney Lake in the interior of British Columbia (mahoneylake.txt), and Mono Lake in California (monolake.txt). Mono and Mahoney Lake are SALINE lakes. In all cases the bicarbonate concentrations are not known. Using the charge balance, estimate what these concentrations might be (i.e. so that the overall charge balance is zero) and then compute the conductivities of these waters.
• PLOT: A figure that will allow you to compare the relative composition of seawater and all 3 other water types. Be creative!
• TEXT: The dominant positive ion for seawater is Na+, and the dominant negative ion is Cl- (that is, these have the greatest concentrations in mol/l). Using your figure, determine (and state) the dominant positive and negative ion for the other water types.
• OUTPUT: A table containing the name of the lake, the input or calculated bicarbonate concentration, the conductivity of the water, and the α ratio. Use fprintf!


5 HAND IN AS HARDCOPY 

• all items requested as PLOT in the form of a plot. Pay attention to the quality of the plots as part of your mark will involve plot quality as well the correctness of the results.
• all items requested as TEXT in the form of written text
• all items requested as OUTPUT in the form of a printed file
• a printout of your assign2.m script and the other functions you write.
• Electronically submit the partner.m file described next. Not handing this in will result in marks being deducted!

ASSIGNMENTS CAN BE DONE WITH OTHERS, AS PER THE LABS. Each person must hand in their own as- signment, but you MUST document the degree of collaboration. This will be done by submitting a file partner.m via VISTA. The file will contain the following lines:

partner.name='YYYYYY'; partner.stu='ZZZZ'; partner.collab='AAAA'; Time_spent= XX;

where the .collab string is a phrase like 'checked answers only', 'worked whole assignment together', or some other brief statement that describes your collaboration.

If you worked alone, you must STILL submit the file (we would like to know how many people worked alone!) but you can write the word NONE for all three partner information strings, or something like 'various people about minor issues', or...

Reference no: EM131110985

Questions Cloud

Account for this dramatic turnover : One company had 40 percent of its workers and 20 percent of its managers resign during the first year after reorganizing into teams. What might account for this dramatic turnover? How might managers ensure a smooth transition to teams?
Expatriate management practices : Critically analyze AstraZeneca's expatriate management practices. According to the 2007 Expatriate Work/Life Balance Survey, 65% of expats report feeling the strain of managing the demands of work and home, leading to more anxieties at home and at ..
Internal control and fraud : Stephanie Baskill, an unemployed accounting clerk, lives one block from Cleaver Manufacturing Company. While walking her dog last year, she noticed some ERP manuals in the dumpsters. Curious, she took the manuals home with her.
What is the steady-state temperature of the aluminum-brass : The free end of the copper rod is maintained at water"s boiling point, and the free end of the brass rod is maintained at water"s freezing point.
Parse and load data files and deal with missing data : To write code to- parse and load data files and deal with missing data,- implement a more complex program involving multiple function calls. - output nicely formatted results and figures summarizing your analyses.
Critical review questions from chapter four : Do you believe that managers today are using more boss- or more subordinate-centered leadership styles? Explain!
Direct claim short door for tall player : As the owner of Contempo Interiors, you recently worked on the custom Indiana home of an NBA basketball player. He requested an oversized 12-foot mahogany entry door. You ordered by telephone the solid mahogany door ("Provence") from American Cust..
Statement of comprehensive income : HY is registered for VAT in Country X. HY purchased a consignment of goods for $70,000 plus VAT at the standard rate and then sold the goods for $138,000 inclusive of VAT at the standard rate. How much profit should HY record in its statement of c..
Find the torque t on the conductor segment : Find the torque T on the conductor segment about an origin at point P (1,0,0) as a function of l(i.e. the solution will be an equation for T as a function of the parameter l).

Reviews

Write a Review

 

MATLAB Programming Questions & Answers

  Program that prompts the user to enter grades in a loop

Write a main program that prompts the user to enter grades in a loop, ending on a negative number, stores the grades in a vector, and asks the user for a passing grade. Ten pass the grade vector and passing cutoff to the function and print the per..

  Calculate an approximation to the energy consumed

Calculate an approximation to the energy consumed over the period and calculate an approximation to the energy consumed over the period t = a to t = b.

  Create a program to print given sequence

A Fibonacci sequence is composed of elements created by adding the two previous elements. Below is the simplest Fibonacci sequence. Create a program to print above sequence in the command window. Use 'For' loop to implement the logic given in the fi..

  A volume 10 in long 5in wide and 05 in thick is to be

a volume 10 in. long 5in wide and 0.5 in. thick is to be removed by face milling cutter that is 3in. diameter and has 6

  Considered to equal when the result of one array subtract

Two arrays are considered to be equal when the result of one array subtracted from the other is an array of zeros. In the script file, create the MATLAB commands to prove the following relationships (use arrays that you makeup yourself)

  Write a matlab program to analyze a patients ecg signal

Determine the Heart Rate of an ECG Recording of Unknown properties Using MATLAB - Write a MATLAB program to analyze a patient's ECG signal and provide warnings if the heart rate becomes either dangerously low or dangerously high.

  Write a program to compute a

Write a program to compute A. Test it with P = $55,000 and interest rate of 6.6% (i = 0.066). Compute results for n = 1, 2, 3, 4, and 5 and display the results as a table with headings and columns for n and A

  Jacobian needed for newtons method

Write a Sci/Matlab function that returns the function values and the Jacobian needed for Newton's method .

  write a function under the name "write2"

a)Write a function under the name "write2" so that it will save the diagonal component of the given matrix...

  Which degree do you think best represents the data

Write a Matlab script to try fitting a 1st, 2nd, and 3rd degree polynomial to the dataset described by volume of water vs. volume of ice. Use subplot to draw all three

  Create functions in file

Create Functions in File and how to code this function - Declare function inputs, and outputs

  Generate by means data.m an array

Generate by measdata.m an array A withsize (365,24), containing temperature measurements for an entire year [1 January,..., 31 December], 24 hours a day [00.00h,...,23.00h].

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd