Fractional derivative to solve ODE in the sense of Caputo

16 vues (au cours des 30 derniers jours)
ghalya alkindi
ghalya alkindi le 1 Mai 2020
I tried to write a matlab code for this Derivative
this to solve ODE :
I write this matlab code
but I dont know where is the error.
% Numerical method
% Initial conditions and setup
h = 0.01; % step size
x = 0:h:1; % the range of x
a=0.5;
y = zeros(size(x)); % allocate the result y
y(0) = 1; % the initial y value
n = numel(y); % the number of y values
% The loop to solve the DE
for j=0:n
b=((j+1).^1-a)-j.^1-a;
for k=0:n
f = (x(k)+2*(y(k)));
y(k+1)=f;
end
%here will be the implicit solution.
end
d=y(k+1).*b;
S=h-a;
G=gamma(2-a);
F=(S./G)*d;
plot(x,F)

Réponses (1)

Guru Mohanty
Guru Mohanty le 4 Mai 2020
Hi, I have gone through your code. I think you are getting Array indexing error. Its due to these following reasons.
  1. In this statement
y = zeros(size(x)); % allocate the result y
y(0) = 1; % the initial y value
The code trying to access Zeroth element, but as we know Array indexing in MATLAB is always positive, i.e. It will start from ‘1’.
To set initial value of y you can do
y(1) = 1;
2. Also, in the for loop you should start indexing from ‘1’ instead of ‘0’. i.e.
for j=1:n
% Expression
end

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by