ngr 0012 (04-1) LecNotes 10-01 working toward a script that will help analyze data ig” steps in accomplishing goal Load data from file (have already created functio 2. Display options 1. linear fit with equation and error 2. semi-log fit with equation and error 3. log-log fit with equation and error 4. linear display with polynomial-fit equation a 5. linear display with spline-fit 3. Quantitative output to screen
working toward a script that will help analyze data. “Big” steps in accomplishing goal. 1. Load data from file (have already created function). 2. Display options. 1. linear fit with equation and error. 2. semi-log fit with equation and error. 3. log-log fit with equation and error. - PowerPoint PPT Presentation
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Engr 0012 (04-1) LecNotes 10-01
working toward a script that will help analyze data
“Big” steps in accomplishing goal
1. Load data from file (have already created function)
2. Display options
1. linear fit with equation and error
2. semi-log fit with equation and error
3. log-log fit with equation and error
4. linear display with polynomial-fit equation and error
5. linear display with spline-fit
3. Quantitative output to screen
Engr 0012 (04-1) LecNotes 10-02
PolynomialsMonomial
A single term of the form anxn where an is a constant and n is either zero (0) or a positive integer
examples
2.37x3 1.0 (3/2)x7
which of these are monomials?
2x sin(x)X sin(3/2)x4 (3-x)x2X
Engr 0012 (04-1) LecNotes 10-03
PolynomialsPolynomial
A function that is the sum of a finite number of monomials.
examples
f(x) = x3 - 5x +7 (z) = (3/2)z7
which of these are polynomials?
d(t) = ½at2 + v0t + d0
y = 3x3 - 2x2 + x f(x) = 2x2 - 3tan(x)
g(z) = (1-z)2 h(t) = 3t2 - 2t-1
XX
Engr 0012 (04-1) LecNotes 10-04
PolynomialsGeneral Form
y = f(x) = anxn + an-1xn-1 + … + a1x + a0
MATLAB
P = [an, an-1, …, a1, a0]Coefficient vector
If P is known, polynomial is completely defined
y = f(x) = P(1)xn + P(2)xn-1 + … + P(n)x + P(n+1)
(n+1) elements
1 + a0x0
frequently omitted
Engr 0012 (04-1) LecNotes 10-05
PolynomialsMATLAB implementation
>> P = 1:4P = 1 2 3 4
>> P(1)ans = 1
can access individualelements of vectors
Evaluate y = f(x) at x = 2 using P vector just defined
y = f(x) = P(1)xn + P(2)xn-1 + … + P(n)x + P(n+1)
>> x=2;
>> fatx = 0;>> for (i=1:1:4) fatx = fatx + P(i)*x^(4-i);end % for loop
first introduction to a loopinitializationtype
index
counting limits/step size
loop body
this loop sums a series of numbers>> fatxfatx = 26
>> fatx2 = polyval(P,x)fatx2 = 26
MATLAB function that executesloop to evaluate a polynomial
Data analysis >> hold on>> loglog(xfit,yfit,'r-')>> hold off
created a log-logplot with:original data points shown as asteriskslog-log fit shown as a line
Engr 0012 (04-1) LecNotes 10-13
Data analysisLooks good - but we took log of data to createWhat if any of the data are negative?
Exponential fit
BxAey Take logarithms
)ln()ln( ABxy
Need to delete any negative y-data and associated x-data
% filter data for semi-log fit newx = [ ]; newy = [ ]; for i = 1:1:length(xdata) if ( ydata(i) > 0 ) newx = [newx xdata(i)]; newy = [newy ydata(i)]; end end
Easier to identify data to keep!!!
Engr 0012 (04-1) LecNotes 10-14
Data analysisto use the extracted data set: polyfit
% add line fit to graphical display semilogy(xnew,ynew,'r*', xfit,yfit,'r-')
% determine fit to data semilogcoef = polyfit(xnew,log(ynew),1); B = semilogcoef(1); A = exp(semilogcoef(2));
% create (xfit,yfit) for line plot xfit = linspace(xnew(1),xnew(length(xnew)),200); yfit = A*exp(B*xfit);
% add line fit to graphical display semilogy(xnew,ynew,'r*') hold on semilogy(xfit,yfit,'r-') hold off
OR
Engr 0012 (04-1) LecNotes 10-15
general strategy for graphical display% filter data set (if necessary)