- In this statement
Fractional derivative to solve ODE in the sense of Caputo
조회 수: 27 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
답변 (1개)
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.
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!