Fractional derivative to solve ODE in the sense of Caputo

조회 수: 27 (최근 30일)
ghalya alkindi
ghalya alkindi 2020년 5월 1일
답변: Guru Mohanty 2020년 5월 4일
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)

답변 (1개)

Guru Mohanty
Guru Mohanty 2020년 5월 4일
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by