Differentiation using diff command

1 vue (au cours des 30 derniers jours)
hm
hm le 3 Fév 2019
Commenté : hm le 3 Fév 2019
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 commentaires
Walter Roberson
Walter Roberson le 3 Fév 2019
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 le 3 Fév 2019
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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Surrogate Optimization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by