Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

the first picture is the problem statement and the second is the code to be modi

ID: 3880016 • Letter: T

Question

the first picture is the problem statement and the second is the code to be modified

Problem Description One way that MATLAB can be used is for data analysis. One common application is generating a model of a natural event from data collected by observing the event. In this assignment, you will have data about how a bacterial agent can cause toxic waste from a chemical process to decompose. Provided with the concentration of toxic waste from process A (given in mol L) and the time that concentration was measured, one can model the concentration of toxic waste from process A as CAab In this equation, CA Is the concentration of toxic waste from process A, t is time, e is Euler's number and and b are parameters. In this instance, we want to find values for and b that minimize the error between what our model predicts the concentration will be at a given time and the actual measurement at an actual time Taking the natural log of the equation CA = adl produces the linear equation m CA-In a + bt. The least squares method can be used to find the line that best fits a set of z/y data points (in our case, t and hn CA). For the equation y = + r, the values of and that minimize the squared error between the predicted and actual value can be found from a collection of n data points (corresponding X and Y values) with the equations and Te re and the statistical measure of degree to which changes i one variable affect the changes in the value of another is given by a correlation coefficient which is given by the equation: and the measure of similarity between two non-zero vectors can be obtaed by cosine similarity as: C8) For our purposes, considerY to be In CA and X to be t from our measured samples. Therefore, a will have to be calculated as en and b will have to be calculated as Hint With our representations of X and Y as column vectors, XY = Xy Rationale Usng MATI.AB relies on being able to uand manipulate vectors and matrices. Thns assgnment attempts to do that in a unique way

Explanation / Answer

Matlab function

function [a,b,r,cs] = modelDecomposition( t,C_A )
% INPUTS
%     t = times when measurements of the concentration were made
%     C_A = Concentration at the corresponding times
% OUTPUT
%     a = parameter in the equation for the model
%     b = parameter in the equation for the model
%     r = correlation coefficient
%     cs = cosine similarity
n = length(t); % number of data points given
X = t; % taking x data sets as time t
Y = log(C_A); % Taking Y data sets as In(C_A)
b = (n*X*Y'-sum(X)*sum(Y))/(n*(X*X')-sum(X)^2);% computing the value of b
Alpha = sum(Y)/n-b*sum(X)/n; % Computing the value of Alpha
a = exp(Alpha); % Computing a from alpha
r = (n*X*Y'-sum(X)*sum(Y))/sqrt((n*(X*X')-sum(X)^2)*(n*(Y*Y')-sum(Y)^2)); % correlation coefficient
cs = X*Y'/(sqrt(X*X')*sqrt(Y*Y')); % cosine similarity
end % End of function


Sample OUTPUT

>> A = 0.3;B = 0.1; % Coefficients
>> t = 0:0.1:0.4; % Time
>> C_A = A*exp(B*t); % model value (exact)
>> [a,b,r,cs] = modelDecomposition( t,C_A ) % Calling the function

a =

    0.3000


b =

    0.1000


r =

    1.0000


cs =

   -0.8095

>>

Result

The coefficients/ parameters are matchin