How get this program to calculate derivative properly?

18 ビュー (過去 30 日間)
Jaroslaw Dabrowski
Jaroslaw Dabrowski 2020 年 4 月 2 日
コメント済み: darova 2020 年 4 月 2 日
function [Yn]=Jaroslaw_Dabrowski(dt, N)
% Help funkcji [Yn]=Jaroslaw_Dabrowski(dt, N)
%funkcja obliczna pochodne n-tego stopnia i rysuje ich wykres.
%Zmienne wejściowe: dt - odstępy czasowe,
% N - stopień pochodnej.
%Zmienne wyjściowe: Yn - obliczona pochodna.
A=2;
w=1;
hold on
if N>10;
error ('myApp:argChk','Decrease the number of loop iterations')
elseif N<=10;
for i=1:N;
t=-3*pi:dt:3*pi;
Yn=A*sin(w*t);
Ynn=A*sin(w*(t+dt));
Yn(189)=Ynn(188);
size(t);
size(Yn);
dYn=diff(Yn,i)./dt;
size(t);
dYn(189)=dYn(1);
size(dYn);
subplot(5,2,i)
grid on
plot(t,dYn)
xlabel('Time')
ylabel('Amplitude')
legend(strcat('Y_n, n=',num2str(i)))
end
end
end
  3 件のコメント
Jaroslaw Dabrowski
Jaroslaw Dabrowski 2020 年 4 月 2 日
Sorry, i missed answer. Could you check the answer below?
darova
darova 2020 年 4 月 2 日
No matter how much you take derivative cos() will be always the same frequency
So your function does return correct output

サインインしてコメントする。

回答 (2 件)

KSSV
KSSV 2020 年 4 月 2 日
Yn=A*sin(w*t);
dYn = A*w*cos(w*t) ;
  2 件のコメント
KSSV
KSSV 2020 年 4 月 2 日
Replace:
dYn=diff(Yn,i)./dt;
with:
dYn=diff(Yn)./dt;
Jaroslaw Dabrowski
Jaroslaw Dabrowski 2020 年 4 月 2 日
It won't work like that. i must be there, becouse each plot must be in higher derivative.

サインインしてコメントする。


Jaroslaw Dabrowski
Jaroslaw Dabrowski 2020 年 4 月 2 日
It should be like that. Theoretically derivative is wrong in my code, and i have no idea how to correct it

Community Treasure Hunt

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

Start Hunting!

Translated by