Matlab code for the following
이전 댓글 표시
How do i use central differencing for x=sint(t) over the interval 0 to 2pi with 2nd order accuracy?
답변 (1개)
Jan
2017년 7월 25일
Is this a homework? If so, what have you tried so far? You need 2 lines of code only and revealing the solution might be counter-productive.
Remember the definition of central differences:
dx(i) = (x(i+1) - x(i-1)) / (t(i+1) - t(i-1))
This can be simplified, because t is evenly spaced.
t = linspace(0, 2*pi, 100);
dt = t(2) - t(1);
If it is not a homework, you can find many tools for central differences in the FileExchange, e.g. the fast C-Mex https://www.mathworks.com/matlabcentral/fileexchange/29887-dgradient, which replies 2nd order approximations with even and not even spacing.
댓글 수: 2
Velika D'Souza
2017년 7월 25일
편집: Jan
2017년 7월 27일
k > 2.513 ??? If k starts at 1, X(k-1) and X(k-2) is not defined. At the margins you cannot use the double sides quotient of differences. So you have to explain, what you want to use instead.
The show formula are not backward and forward differences. This would change the indices, not only the sign of the output.
You did not answer my question if this is a homework. It is easier to assist you, when this is clear.
It seems like you have confused the formula for the 1st order approximation of the 2nd derivative with the 2nd order method for the 1st derivative. "Central differences" means:
Y = (X(3:end) - X(1:end-2)) / (2 * dt)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!