-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_animated_deriv.m
53 lines (43 loc) · 1.02 KB
/
test_animated_deriv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% Performs derivation of x(t) = t, using alpha from 0 to 1, and animate
% the result using a GIF file
clc;
close all;
clear all;
ts = 0.01;
n = 170;
figure;
hold on;
h1 = plot(0, 0, 'r');
h3 = plot(0, 0, 'm');
h2 = plot(0, 0, 'b');
h4 = text(0.2, 1.8, '');
legend('\alpha = 0','\alpha = 1', '0<\alpha< 1')
xlabel('t');
ylabel('x(t)')
title ('Fractional Derivative')
t = 0:ts:2;
% x(t) = t
x = t;
set(h1, 'XData', t, 'YData', x);
% x(t) = 1
x3 = fderiv(x, 1, n, ts);
set(h3, 'XData', t, 'YData', x3);
k = 1; % frame number for the gif file
for alpha = 0:0.05:1
stralpha = ['\alpha = ', num2str(alpha)];
set(h4, 'String', stralpha);
x2 = fderiv(x, alpha, n, ts);
set(h2, 'XData', t, 'YData', x2);
drawnow;
pause(0.1);
% Draw to gif
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if k == 1;
imwrite(imind,cm,'fderiv.gif','gif', 'Loopcount',inf);
else
imwrite(imind,cm,'fderiv.gif','gif','WriteMode','append');
end
k = k + 1;
end