Differentiation using diff command

조회 수: 5 (최근 30일)
hm
hm 2019년 2월 3일
댓글: hm 2019년 2월 3일
Hi I am using diff command and in the end I need to compare the actual differential value with the one I am getting after using diff command, here is my code
Please tell me how can I get the correct value so as the relation can be built between the error and step size, i.e smaller the step size( or in other words greater the samples) smaller will be the error and results will get closer to the actual value my code is:
dt=0.01; %dt=1,0.1,0.01
t=0:dt:2*pi;
x=sin(t);
yt=cos(t); %mathematical differential
dx=diff(x)./dt;
dx=[0;dx(:)]'% Making its length equal to the vector yt since we are padding a zero here it gives incorrect results
y_sum=sum(yt)
x_sum=sum(dx)
error=yt-dx;
sum_error=sum(error)
Because this code is giving me opposite results
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 2월 3일
When you calculate
y_sum=sum(yt)
you are approximating integral of cos(t) from t = 0 to t = 2 * pi, if you were multiplying by dt. But your dx has been divided by dt.
hm
hm 2019년 2월 3일
oh yes thaaanks, but the worst part is sum of errors is where the error goes how can i get a relation between the two smaples and error

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by