How to fit a log plot to a set of data

11 views (last 30 days)
I have a vector of pressure data over a certain time period and I have made a plot of the data
using plot(time,pressure)
From the plot, it looks like the line of data is close to a log curve. I want to insert a log fit into my plot. Can this be done in MATLAB?
Thanks

Accepted Answer

Star Strider
Star Strider on 8 Jul 2014
It can be done, but it depends on what you mean by ‘log fit’. Without seeing your data, I can’t suggest an approach.
In the physical sense at least, pressure is not to my knowledge a function of time, but of temperature and volume. That lends itself to a physical model that is likely a better and more appropriate fit to your data than would be modeling it as a function of time.
  2 Comments
Star Strider
Star Strider on 8 Jul 2014
If you have a mathematical model of your data of which you want to estimate the parameters, that’s definitely possible.
If you don’t have one, I suggest an asymptotic function such as:
P(t) = Pmax * (1 - exp(K*t))
which as an anonymous function becomes:
P = @(b,t) b(1) .* (1 - exp(b(2).*t));
The reason is that the log function is monotonically increasing (to infinity, which I hope is not what your pressure curve actually does) while the asymptotic function is eventually bounded at Pmax for all t. You can easily fit the function with fminsearch if you don’t have access to the Statistics Toolbox nlinfit function or the Optimization Toolbox lsqcurvefit function.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by