Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*****PLEASE DO IN MATLAB***** A. Reading data from a file for plotting and exploration : Given a (plain text!) file containing N columns of values,

*****PLEASE DO IN MATLAB*****

A. Reading data from a file for plotting and exploration : Given a (plain text!) file containing N columns of values, we need to read the values into matlab for exploration and plotting. To do this, we need to know the name of the file, and how data is arranged in it, so need to view it in (a plain text!) editor. 1. Write a script "readFile.m" which: a. reads a given file "file.dat" into a matrix "mat", b. extracts the columns of the data from "mat" into arrays "c1", "c2", ..., "cN", c. plots some column versus another column, with a title, and labeled axes. To test and debug your code, create a "file.dat" with 3 rows and N=2 columns ( so a 32 matrix ). The first column should be sorted. You can just enter some numbers in "file.dat" in an editor. Next, test it on a 43 array to make sure it also works. Insert brief comments in you code to document what is being done. 2. To apply this on real data, I am providing a data file, produced by a code that implements a mathematical model for bacterial chemotaxis (by numerical solution of a system of Partial Differential Equations). The file prof300s.dat contains profiles (values at a grid of locations x(i) at some particular time, here at 300sec) of several quantities, labeled by column at the top ( x(i) C(i) B(i) etc ). The last column is the index "i" of x(i). Of main interest is the 3rd column, labeled "B(i)". It represents bacterial density at location x(i), at the output time (normalized, B(i) means B(i)109 cells/mL). It has a "bump", and want to find its FWHM, i.e. the width of the interval [xLeft, xRight] where a horizontal line at half-maximum height intersects the bump. Biologically, this is the width of the "band" the bacteria form during chemotaxis. B. Plotting 1. Download the file prof300s.dat and save it as "prof300s.dat" . View it in an editor to see its contents. The first two lines contain labels, need to be read over with fgetl . The rest of the lines are numerical values to be scanned into a matrix, say "mat". You can see what the B-profile looks like easily in gnuplot: gnuplot> plot "prof300s.dat" u 1:3 w lines lw 2 2. Copy your "readFile.m" to "Lab8.m" and modify appropriately to achieve the following: a. Read the data from "prof300s.dat" into a matrix "mat". b. Extract each column (which is now a row of "mat") into a vector (with sensible names: x , C , B , ... ). Only need x and B, so may extract only those. Suppress output with ";", they are long... c. Find Bmax = maximum value of B, and at which index it occurs, iBmax. Set cut = Bmax/2 . Print Bmax and cut nicely (with fprintf). Run your code to make sure it produces values of Bmax, cut. d. Plot B vs x, as a red curve. Label the axes. The units of x are micrometers (m). B is dimensionless. Run your code to make sure it produces the plot. e. To see where we are cutting the bump, also plot the line at height cut, on the same plot, as a black horizontal line. [Note: Once you know the value of "cut", say 1.5, it's easy to do it in Gnuplot (outside of Matlab): gnuplot> cut=1.5; plot "prof300s.dat" u 1:3 w lines lw 2 , cut lw 3 ] To do this in Matlab, will need to create an array, call it "cutArray", of same length as x, with constant values = cut. Again, run your code to make sure it produces the plot with both the bump and the cut-line. f. Is this value of cut a good choice here? does it really represent half-maximum of the bump ? (note that the "base" value of B is 1, not zero). Figure out a better expression for setting "cut". C. Find FWHM numerically, from arrays of points. 1. Create a Matlab function in a file "fwhm.m", which accepts two arrays (x, y) as input, and returns FWHM of y, by implementing the following algorithm (discussed in Part 5 of HW1).

Find the maximum value Peak of y, and the index where it occurs, iPeak .

Set the cutoff level at half maximum: cut = Peak/2, or more appropriately from B.2.f.

Find the first point xi (before iPeak) at which yi cut. Call it xLeft.

Find the first xi (after iPeak) at which yi cut. Call it xRight.

Then FWHM = xRight xLeft . 2. Modify your "Lab8.m" code to: a. Call the fwhm function with arguments (x, B) to find the FWHM of the B array. b. Then print it out (nicely, with fprintf) to say: "FWHM of bacteria at time 300 sec is" FWHM_value "microns, at height" cut_value

# prof300s.out* : profile at time: 300.010, nsteps= 20763 # x(i) C(i) B(i) R(i) L(i) i 0.000000 1.000000 0.219202 0.109601 0.109601 0 3.906250 0.989112 0.219204 0.109603 0.109601 1 11.718750 0.967404 0.219203 0.109605 0.109599 2 19.531250 0.945765 0.219202 0.109606 0.109596 3 27.343750 0.924195 0.219199 0.109606 0.109593 4 35.156250 0.902693 0.219196 0.109606 0.109589 5 42.968750 0.881260 0.219192 0.109606 0.109585 6 50.781250 0.859895 0.219186 0.109605 0.109581 7 58.593750 0.838599 0.219181 0.109604 0.109576 8 66.406250 0.817372 0.219174 0.109603 0.109571 9 74.218750 0.796213 0.219166 0.109601 0.109566 10 82.031250 0.775123 0.219158 0.109598 0.109560 11 89.843750 0.754101 0.219149 0.109595 0.109554 12 97.656250 0.733148 0.219140 0.109592 0.109547 13 105.468750 0.712264 0.219129 0.109589 0.109541 14 113.281250 0.691448 0.219118 0.109584 0.109534 15 121.093750 0.670701 0.219106 0.109580 0.109526 16 128.906250 0.650022 0.219094 0.109575 0.109519 17 136.718750 0.629412 0.219081 0.109570 0.109511 18 144.531250 0.608870 0.219067 0.109565 0.109503 19 152.343750 0.588397 0.219053 0.109559 0.109494 20 160.156250 0.567993 0.219038 0.109552 0.109486 21 167.968750 0.547657 0.219023 0.109546 0.109477 22 175.781250 0.527390 0.219008 0.109539 0.109468 23 183.593750 0.507191 0.218991 0.109532 0.109460 24 191.406250 0.487061 0.218975 0.109525 0.109451 25 199.218750 0.466999 0.232351 0.122910 0.109441 26 207.031250 0.447010 0.260759 0.137933 0.122825 27 214.843750 0.427103 0.292642 0.154795 0.137847 28 222.656250 0.407287 0.328426 0.173719 0.154707 29 230.468750 0.387574 0.368589 0.194959 0.173630 30 238.281250 0.367977 0.413667 0.218798 0.194869 31 246.093750 0.348508 0.464261 0.245554 0.218707 32 253.906250 0.329186 0.521047 0.275584 0.245463 33 261.718750 0.310026 0.584782 0.309289 0.275492 34 269.531250 0.291049 0.656316 0.347119 0.309197 35 277.343750 0.272278 0.736604 0.389577 0.347027 36 285.156250 0.253737 0.826718 0.437232 0.389486 37 292.968750 0.235455 0.927861 0.490719 0.437142 38 300.781250 0.217463 1.041381 0.550751 0.490630 39 308.593750 0.199797 1.168794 0.618130 0.550664 40 316.406250 0.182497 1.311800 0.693755 0.618045 41 324.218750 0.165608 1.472309 0.778635 0.693674 42 332.031250 0.149179 1.652461 0.873903 0.778558 43 339.843750 0.133268 1.949377 1.075546 0.873830 44 347.656250 0.117966 2.399202 1.323723 1.075479 45 355.468750 0.103416 2.952837 1.629173 1.323664 46 363.281250 0.089789 3.258280 1.629156 1.629124 47 371.093750 0.077183 3.258260 1.629142 1.629119 48 378.906250 0.065596 3.258247 1.629130 1.629116 49 386.718750 0.055030 3.258240 1.629122 1.629118 50 394.531250 0.045482 3.258240 1.629118 1.629122 51 402.343750 0.036957 3.258248 1.629117 1.629131 52 410.156250 0.029446 3.258263 1.629119 1.629144 53 417.968750 0.022963 3.258286 1.629125 1.629161 54 425.781250 0.017487 3.258317 1.629135 1.629181 55 433.593750 0.013053 2.952880 1.323674 1.629206 56 441.406250 0.009506 2.399247 1.075489 1.323758 57 449.218750 0.006772 1.949423 0.873840 1.075583 58 457.031250 0.004543 1.652510 0.778568 0.873941 59 464.843750 0.003008 1.472359 0.693685 0.778674 60 472.656250 0.001641 1.311850 0.618058 0.693792 61 480.468750 0.001172 1.168865 0.550677 0.618187 62 488.281250 0.000245 1.068017 0.517977 0.550040 63 496.093750 0.000664 1.006354 0.488242 0.518112 64 503.906250 0.000046 0.959012 0.471337 0.487675 65 511.718750 0.000397 0.939909 0.469854 0.470055 66 519.531250 0.000134 0.940004 0.469914 0.470090 67 527.343750 0.000291 0.940052 0.469924 0.470128 68 535.156250 0.000198 0.940097 0.469927 0.470170 69 542.968750 0.000252 0.940153 0.469937 0.470216 70 550.781250 0.000217 0.940220 0.469955 0.470266 71 558.593750 0.000236 0.940296 0.469977 0.470319 72 566.406250 0.000223 0.940379 0.470003 0.470376 73 574.218750 0.000229 0.940469 0.470033 0.470436 74 582.031250 0.000224 0.940567 0.470067 0.470500 75 589.843750 0.000225 0.940672 0.470104 0.470567 76 597.656250 0.000222 0.940784 0.470145 0.470638 77 605.468750 0.000221 0.940902 0.470190 0.470712 78 613.281250 0.000220 0.941027 0.470238 0.470790 79 621.093750 0.000219 0.941160 0.470289 0.470870 80 628.906250 0.000217 0.941299 0.470344 0.470954 81 636.718750 0.000216 0.941444 0.470402 0.471042 82 644.531250 0.000215 0.941597 0.470464 0.471133 83 652.343750 0.000213 0.941756 0.470530 0.471227 84 660.156250 0.000212 0.941923 0.470598 0.471324 85 667.968750 0.000211 0.942095 0.470671 0.471425 86 675.781250 0.000209 0.942275 0.470746 0.471528 87 683.593750 0.000208 0.942460 0.470825 0.471635 88 691.406250 0.000207 0.942653 0.470907 0.471745 89 699.218750 0.000206 0.942851 0.470993 0.471859 90 707.031250 0.000204 0.943057 0.471082 0.471975 91 714.843750 0.000203 0.943268 0.471174 0.472094 92 722.656250 0.000202 0.943486 0.471269 0.472217 93 730.468750 0.000200 0.943710 0.471368 0.472342 94 738.281250 0.000199 0.943940 0.471470 0.472470 95 746.093750 0.000198 0.944177 0.471575 0.472602 96 753.906250 0.000197 0.944419 0.471683 0.472736 97 761.718750 0.000195 0.944668 0.471795 0.472873 98 769.531250 0.000194 0.944922 0.471909 0.473013 99 777.343750 0.000193 0.945182 0.472027 0.473155 100 785.156250 0.000191 0.945448 0.472147 0.473301 101 792.968750 0.000190 0.945720 0.472271 0.473449 102 800.781250 0.000189 0.945997 0.472398 0.473600 103 808.593750 0.000188 0.946280 0.472527 0.473753 104 816.406250 0.000186 0.946569 0.472660 0.473909 105 824.218750 0.000185 0.946863 0.472795 0.474067 106 832.031250 0.000184 0.947162 0.472934 0.474228 107 839.843750 0.000183 0.947466 0.473075 0.474391 108 847.656250 0.000181 0.947775 0.473219 0.474557 109 855.468750 0.000180 0.948090 0.473365 0.474725 110 863.281250 0.000179 0.948409 0.473514 0.474895 111 871.093750 0.000178 0.948733 0.473666 0.475067 112 878.906250 0.000176 0.949062 0.473821 0.475242 113 886.718750 0.000175 0.949396 0.473978 0.475419 114 894.531250 0.000174 0.949734 0.474137 0.475597 115 902.343750 0.000173 0.950077 0.474299 0.475778 116 910.156250 0.000171 0.950424 0.474463 0.475961 117 917.968750 0.000170 0.950775 0.474630 0.476145 118 925.781250 0.000169 0.951130 0.474799 0.476332 119 933.593750 0.000168 0.951490 0.474970 0.476520 120 941.406250 0.000166 0.951853 0.475143 0.476710 121 949.218750 0.000165 0.952220 0.475319 0.476902 122 957.031250 0.000164 0.952591 0.475496 0.477095 123 964.843750 0.000163 0.952966 0.475676 0.477290 124 972.656250 0.000162 0.953343 0.475857 0.477486 125 980.468750 0.000160 0.953725 0.476041 0.477684 126 988.281250 0.000159 0.954109 0.476226 0.477883 127 996.093750 0.000158 0.954497 0.476414 0.478083 128 1003.906250 0.000157 0.954888 0.476603 0.478285 129

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

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

LOQ 13-2: How do attitudes and actions interact?

Answered: 1 week ago