Hi Guys,
for n = 3:length(x)
y1 = x(2:n) ;
t1 = ((n-2):-1:0)*dt ;
% y2 = x(1:n-1) ;
y2 = y1 - 1 ;
t2 = t1 +dt;
int(n) = sum (t1.^(k-1)/factorial(k-1).*y1 + t2.^(k-1)/factorial(k-1).*y2)*dt/2 ;end
I want to define y2= y1 -1 instead y2= x (1:n-1) which I have commented above. By y2 = y1 - 1, occurred some errors in MATLAB. Why? It is not correct?
No products are associated with this question.
y1-1 means the vector y1 with the quantity 1 subtracted from it. The commented code shifts the elements by one element. Which do you want to do?
I think you want to shift the elements by 1, but you want to define it your own way. If you want to use Matlab, you need to use it's syntax.
int = zeros(1,length(x));
if k <= 0
int = x ;
return
end
for n = 3:length(x)
y1 = x(2:n) ;
t1 = ((n-2):-1:0)*dt ;
y2 = x(1:n-1) ; % y2 = -1 +y1 ;
t2 = t1 +dt;
int(n) = sum (t1.^(k-1)/factorial(k-1).*y1 + t2.^(k-1)/factorial(k-1).*y2)*dt/2 ;end
I mean, is there anyway to define y2 from y1? And not from variable x? Could I omit the variable y2 from the code ?
1 Comment
Direct link to this comment:
http://mathworks.com/matlabcentral/answers/42827#comment_88091
What error did you encounter with the code you tried?