Differentiation using diff command
1 回表示 (過去 30 日間)
古いコメントを表示
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
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.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surrogate Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!