backward,forward, and central Difference

Can any body help me understand how to do numerical differentiation? example:
t = 0:5:100; Z = cos(10*pi*t)+sin(35*pi*5);
how can I find the backward,forward and central difference at t = 99?

답변 (4개)

Jan
Jan 2011년 11월 9일

2 개 추천

For :
t = 0:5:100;
Z(t) = cos(10*pi*t)+sin(35*pi*5);
you cannot find the forward and central difference for t=100, because this is the last point. Central differences needs one neighboring in each direction, therefore they can be computed for interior points only. For the first point, you can get a forwrad difference, for the last point a backward difference only:
dZ1 = (Z(2) - Z(1)) / (t(2) - t(1));
dzi = (Z(i+2) - Z(i-1)) / (t(i+1) - t(i-1)); % 1 < i < 100
dZ100 = (Z(100) - Z(99)) / (t(100) - t(99));

댓글 수: 4

Abra dog
Abra dog 2011년 11월 9일
so if it was 99 I can find the central and forward difference?
Titus Edelhofer
Titus Edelhofer 2011년 11월 9일
No: forward difference means "use this point plus point to the right". Regardless how many points you have, the last (the most right point) never has a point to the right. Therefore you have to use backward difference at the right boundary...
Abra dog
Abra dog 2011년 11월 9일
oh ok but what if instead of t = 0:5:100, t = 99?
Jan
Jan 2011년 11월 9일
The point t=99 is not a member of t=0:5:100.

댓글을 달려면 로그인하십시오.

Friedrich
Friedrich 2011년 11월 9일

1 개 추천

Hi,
lets say you like to get Z'(t_0) with the forward difference. You do the following
Z'(t_0) = ( Z(t_0 + h) - Z(t_0) ) / h
where h is a small offset. You actually calculate the slope of a straight line which goes through Z(t_0 + h) and Z(t_0) for forward differences.

댓글 수: 4

Abra dog
Abra dog 2011년 11월 9일
umm can you define a small offset?
Jan
Jan 2011년 11월 9일
It is not possible to define "small" uniquely for this problem. If h is too large, the error of higher orders will increase: The change in the function value does depend on the 2nd, 3rd, etc derivative also. If h is too small, both function values will be nearly identical and due to the limited number of digits the result will have a small accuracy only: 1.2345678 - 1.2345679 = 0.0000001. If you divide this small number by a tiny h you get more or less random values. Therefore a rule of thumb is to calculate h such that (Z(t)-Z(t+h)) has about the half number of significant digits, for DOUBLEs this is about 7. In other words: (Z(t)-Z(t+h)) should be about SQRT(EPS).
If you have discrete data, the situation is easier: Then you use the neighboring elements. This is not very accurate, but the best possible solution.
Abra dog
Abra dog 2011년 11월 9일
ok so i found out that h is .125 so to find forward difference I just type
z'forward = ((x+h)-x)/h?
if i do that i get 1
Friedrich
Friedrich 2011년 11월 10일
No, i would put it in the formula above (t_0 = x in that case).
So (cos(10*pi*(x+h)) + sin(35*pi*5) - .....) / h

댓글을 달려면 로그인하십시오.

Fahad Maqsood
Fahad Maqsood 2018년 12월 9일

0 개 추천

Hi
I am new to matlab and struggling with it. any one who can help me getting started
Given: x 1 2 3 4 5 6
f(x) 2 3 1 5 4 1
Estimate f′(4) using the forward, backward, and centered difference method with h = 1.
and second order polynomial.

댓글 수: 3

John D'Errico
John D'Errico 2018년 12월 9일
Please don't add an answer, resurrecting an old question, just to add a new question, even if it is vaguely related. Anyway, this was your homework assignment. So you need to make some effort. What have you tried? If nothing, then why not?
So start by writing down the formula that you need to use.
Fahad Maqsood
Fahad Maqsood 2018년 12월 13일
As i mentioned i never worked on matlab before, i searched hard for it but could not find any related problems. It has been posted for those could help others getting started. Well you have your own opinion keep it in your pocket.
Steven Lord
Steven Lord 2018년 12월 13일
If you show us what you've tried so far and explain the specific difficulty you're experiencing, we may be able to provide some guidance.
If you're not even sure where to start because you're new to MATLAB, I recommend working through the MATLAB Onramp tutorial available from the Tutorials section of the Support page on this website (click the Support button at the top of this page.)
If you're not sure where to start because of the subject matter of the question, I recommend contacting your professor and/or your teaching assistant and asking them for help with the material.

댓글을 달려면 로그인하십시오.

LE TRAN
LE TRAN 2024년 3월 14일

0 개 추천

hello everyone, I have a math problem with an error in the code.Please refer to the code
  1. Build a code to Estimate the first derivative of the following function at x=0.5 using h=0.5, 0.25, and 0.1 for the forward, backward, and centre difference approximation schemes.
  2. Make an analysis and draw some conclusions based on the results obtained.
  3. f(x)= -0,1*x^4-0,15*x^3-0,5*x^2-0,25*x+1,2

댓글 수: 7

LE TRAN
LE TRAN 2024년 3월 14일
help me:((
f = @(x) -0.1*x.^4 - 0.15*x.^3 - 0.5*x.^2 - 0. 25*x + 1.2
LE TRAN
LE TRAN 2024년 3월 14일
yes pro
You said "Please refer to code" but the only code you attached was
f(x)= -0,1*x^4-0,15*x^3-0,5*x^2-0,25*x+1,2
so I corrected that code.
LE TRAN
LE TRAN 2024년 3월 14일
이동: Torsten 2024년 3월 14일
I tried this and some other code for a test run and got an error message hoping you could help me learn through Matlab code, so I don't know very well.
LE TRAN
LE TRAN 2024년 3월 14일
이동: Torsten 2024년 3월 14일
The topic is in the first question comment.thank you so much.
Torsten
Torsten 2024년 3월 14일
편집: Torsten 2024년 3월 14일
We cannot execute and/or correct the graphics with your code. Include your code as plain ascii text.
And it would help if you also included the complete error message you get from this code.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

질문:

2011년 11월 9일

편집:

2024년 3월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by