Help using poly fit to determine equation constants of power function and plotting the linear form
67 views (last 30 days)
- x axis (t) 172 241 392 483 608 812 959 1305
- y axis (h) .20 .60 2.0 4.0 8.0 20.0 40.0 80.0
Using the above data I am required to...
- Enter the data as vectors
- Plot the data and by changing the axes determine the function type
- Using polyfit, determine the equation constants
- Create a plot (using the linear form of the graph)that includes the highlighted data points along with your best fit equation
I entered the data as vectors...
I determined the data represents a power function by plotting it on a log log series
I THINK I determined the constants using the following commands...
If I am correct the 2.9861 represents m and -17.0002 represents b in the equation y=m*x^b
I really don't know how to graph the linear form correctly and I am unsure of how to do it to include the "highlighted data points"
I attempted to do it using the commands...
I am pretty sure the graph isn't correct and there aren't any highlighted points... Any input on what I did wrong and should do differently would be GREATLY appreciated. Thank you in advance.
Jonathan LeSage on 14 Oct 2013
Edited: Jonathan LeSage on 14 Oct 2013
You just need to transform the linear fit coefficients (the outputs from polyfit) from a logarithm scale back to the linear scale you started with. Since you started by transforming your data into a log-log scale, the linear fit will be on the log-log scale.
Your fit (from polyval): log(h) = m*log(t) + b
Returning to the linear scale (take the exponential of each side): h = t^m*exp(b)
Here is some code that illustrates these transformations in side-by-side plots:
% Original data
t = [172,241,392,483,608,812,959,1305];
h = [0.200,0.600,2.00,4.00,8.00,20.00,40.00,80.00];
% Transformation to logarithmic scale
log_t = log(t);
log_h = log(h);
% Linear fit of data in logarithmic scale
fit = polyfit(log_t,log_h,1);
% Generate linear fit curve in the logarithmic scale
xVec = linspace(log_t(1),log_t(end),100);
log_h_fit = polyval(fit,xVec);
% Plot logarithmic data and fit
title('log-log Data Plot')
% Convert from logarithmic scale to linear scale
m = fit(1);
b = fit(2);
h_fit = t.^m*exp(b);
% Plot linear scale
title('Original scale plot')