Help using poly fit to determine equation constants of power function and plotting the linear form

44 Ansichten (letzte 30 Tage)
  • 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...
t=[172,241,392,483,608,812,959,1305]
h=[0.200,0.6.00,2.00,4.00,20.00,40.00,80.00]
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...
>> p=polyfit(log(t),log(h),1)
p =
2.9861 -17.0002
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...
>> m=p(1)
m =
2.9861
>> b=p(2)
b =
-17.0002
>> y=[m*t+b];
>> plot(y)
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.

Akzeptierte Antwort

Jonathan LeSage
Jonathan LeSage am 14 Okt. 2013
Bearbeitet: Jonathan LeSage am 14 Okt. 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
subplot(1,2,1);
plot(xVec,log_h_fit,log_t,log_h,'o');
grid on;
legend('Fit','Data')
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
subplot(1,2,2)
plot(t,t.^fit(1)*exp(fit(2)),t,h,'o');
grid on;
legend('Fit','Data');
title('Original scale plot')

Weitere Antworten (0)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by