Definition of Caputo fractional order system
4 views (last 30 days)
Show older comments
Hello,
I want to code this Caputo fractional order dynamics please guide me to do this in matlab. Of course it can be done with simulink but I want to code it.
Thank you in advance for your help.
0 Comments
Answers (1)
Anurag Ojha
on 12 Jun 2024
Hi Frashid
In order to code this in MATLAB you can refer to the code attached below,I have taken certain assumptions. Kindly modify it according to your use case:
% Parameters
A = [2 0; -1 -2];
B = [1 0; 0 1];
alpha = 0.9;
% Time vector
t = 0:0.01:10;
% Initial condition
x0 = [0; 0];
u = [1; 1];
% Preallocate memory for state vector
x = zeros(2, length(t));
x(:, 1) = x0;
% Compute dynamics
for i = 2:length(t)
dt = t(i) - t(i-1);
dx = A*x(:, i-1) + B*u;
x(:, i) = x(:, i-1) + dt^alpha*dx;
end
% Plot results
figure;
plot(t, x(1, :), 'b', 'LineWidth', 2);
hold on;
plot(t, x(2, :), 'r', 'LineWidth', 2);
xlabel('Time');
ylabel('State');
legend('x_1', 'x_2');
The code above defines the system matrices A and B, the fractional order alpha, and the time vector t. It then initializes the state vector x and computes the dynamics using a loop. Finally, it plots the results.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!