How to find the sum of values of a function at mid point of every subinterval?
1 次查看(过去 30 天)
显示 更早的评论
I am trying to run this code but don't know how to write code for finding value of function F at mid point of subinterval say, if my interval is [ti, ti+1] for i=0,1,2, n. and need to find sum of functional value at every (ti +ti+1)/2. I need to do it for Rsum2 in this code.
clc; clear all; format long
%%%%%%%%%%%%%%%%%%%%%%%%%%
alpha=0.8;% fractional index
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TN=1 % time
N=10
T0=0
tau=TN/N
T=[T0:tau:TN]
X0=0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X(1)=X0
F =@(X,T)=X+T
for n=0:N-1
Rsum=0;
for j=1:1:n+2
Rsum=Rsum+2*F (j)
end
Rsum2=0;
for j=1:1:n+1
Rsum2=Rsum2+4*F (j+1/2)
end
X(n+2)=X(1) +(tau^alpha)*Rsum + (tau^alpha)*Rsum2
end
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!