Fractional derivative to solve ODE in the sense of Caputo

27 Ansichten (letzte 30 Tage)
ghalya alkindi
ghalya alkindi am 1 Mai 2020
Beantwortet: Guru Mohanty am 4 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)

Antworten (1)

Guru Mohanty
Guru Mohanty am 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

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by