numeric - Matlab: diff(interp1(...'pchip')) produces strange results? -


i have following arbitrary data:

t=[0 1 2 3 4 5 6 7 8 9 10 12 14]; c=[0 1 5 8 10 8 6 4 3.0 2.2 1.5 0.6 0]; area=trapz(t,c); e=c./area; f=cumtrapz(t,e); 

when plotted, looks follows: enter image description here

now, want smoothen plots:

t_int=[]; e_int=[]; f_int=[];  xmin=min(t); xmax=max(t); points=5000; stepsize=(xmax-xmin)/points;  i=xmin:stepsize:xmax     t_int=[t_int i];     e_int=[e_int interp1(t, e, i,'pchip')];     f_int=[f_int interp1(t, f, i,'pchip')]; end 

enter image description here

okay, here actual part problem is. in reality, have f plot , corresponding e plot. since f plot integral of e, e differentiated f plot.

so then:

dy=diff(f_int); dx=diff(t_int); dydx = dy./dx; plot(t_int(:,1:length(dydx)),dydx,t_int,e_int) legend('e (calculated)','e (actual)') 

enter image description here

why calculated e plot wonky?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -