Can you help me to plot the derivative of the function.

1 view (last 30 days)
I have a code matlab:
k = 3;
N = 2500;
L = 250;
B = L/N ;
dn = 1/L;
n0 = 0.1;
n = dn : dn : N*dn;
phi = 2*pi*rand(size(n));
Amp1 = sqrt(dn)*(2^k)*(1e-3)*(n0./n);
x = 0:B:L-B;
hx = zeros(size(x));
for i=1:length(x)
hx(i) = sum(Amp1.*cos(2*pi*n*x(i)+ phi));
end
Can you help me to plot the derivative of the function hx(i).
Thank you so much. Have a good day.

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 9 Jan 2021
plot(diff(hx));
https://in.mathworks.com/help/matlab/ref/diff.html
  3 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 11 Jan 2021
If diff, each element is subtracted from the precious one, its not impacted in other ways.
>> A=randi(10,[1,10])
A =
1 3 6 10 10 2 10 10 5 9
>> diff(A)
ans =
2 3 4 0 -8 8 0 -5 4
See the df/dx definition, If h is infinitesimally small, then becomes f(x+h)-f(x)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!