Differentiation using diff command
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 3 Feb. 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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Surrogate Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!