How to adjust sample spacing based on the steepness of a curve?

2 次查看(过去 30 天)
Hi all, I am plotting a curve of the form f(x) = a x^n, where a and n are constant. a is usually some number between 5 to 55 but n could be positive or negative (e.g. one typical value of n is -5/3). I need to plot it in a very large range of x up to 1E6 or 1E8, so I am plotting it in semilogx
x=1:1E6; % I could make it interval even lesser says x=1:0.1:1E6 if needed f=5./(x.^(5/3)); semilogx(x, f, '-o');
Since the curve is very steep, most of the data points are plotted at the tail while I want more points shown on the steepest part and less point on the bottom (or tail part). I try to find the derivative of the curve (says g) and use the absolute slope to control the number of points of each sections
n = find(g>=0.1); newx = x(n); newf = f(n);
It helps a bit, I see more points on the front part while I can reduce the number of the tail so to compress the size of the total samples needed in plotting. But it still not perfect, still have too many points on the tail. So I try to break it in sections say from after x>=100, I search all f with slope less than 0.1 and drops the duplicates. It helps a bit more but still doesn't help much. Or if I change the n, I need to repeat the whole process again until I find another set of sample points. I am wondering if there is any better way to do that. Thanks.
p.s. Actually, for some reason, I need to keep the y axis linear so I cannot use semilogy to plot the data.

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by