フィルターのクリア

Strange slope for points in a curve

3 ビュー (過去 30 日間)
Kyle
Kyle 2014 年 10 月 3 日
コメント済み: Mohammad Abouali 2014 年 10 月 3 日
Dear experts, I want to get the slope for each point from the curve defined below:
x = 1194:1206;
y =[114,115,117,118,119,120,122,123,124,126,127,128,129];
see the attached graph for the curve.
Directly applying the function "gradient" cannt get the correct slope - the slope will jump up an down. It's understandable that I don't have enough data points. I expect the slope changes gradually.
I expect not to use any interpretation or curve fitting method. Any suggestion is welcome. Many thanks

採用された回答

Mohammad Abouali
Mohammad Abouali 2014 年 10 月 3 日
There are two slopes at each point. The left slope and right slope? What you want to do about that?
  2 件のコメント
Kyle
Kyle 2014 年 10 月 3 日
could you please suggest to calculate the right slope?
Mohammad Abouali
Mohammad Abouali 2014 年 10 月 3 日
It gonna still jumps up and down since your lines are not straight any way.
If you want first order accurate first derivatives do this
x = 1194:1206;
y =[114,115,117,118,119,120,122,123,124,126,127,128,129];
dYO1=(y(2:end)-y(1:end-1))./(x(2:end)-x(1:end-1)); % Or in this case it would be the same as diff(y);
figure, plot(x(1:end-1),dYO1,'o-');
You can calculate second order accurate first derivative as follow:
dYO2=(y(3:end)-y(1:end-2))./(x(3:end)-x(1:end-2));
figure, plot(x(2:end-1),dYO2,'ro-')
if you want the slope of the lines themselves (i.e. at the middle of the line) then dYO1 would be the accurate one ( at the center of the lines not at the point themselves)
xc=0.5*(x(1:end-1)+x(2:end));
plot(xc,dYo1);

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2014 年 10 月 3 日
編集済み: Matt J 2014 年 10 月 3 日
You cannot define a derivative without some sort of interpolation model. You can take first differences using diff(y), but that corresponds to a linear interpolation model.
  2 件のコメント
Kyle
Kyle 2014 年 10 月 3 日
I tried using spline() function. Although it enhances the smoothness, the slope vs x still jumps up and down :(
Matt J
Matt J 2014 年 10 月 3 日
The slope is obviously going to jump up and down no matter what you do. Your points don't all lie on a straight line.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by