How to use finite difference to find slope for a function?

조회 수: 3 (최근 30일)
wenchong chen
wenchong chen 2021년 2월 16일
답변: Shubham Khatri 2021년 2월 21일
I have a function F(x)=x^2 + x - 10, how can I creat code for forward, back ward and central finite difference approximation of the slope ? I don't know where can I start.
  댓글 수: 2
dpb
dpb 2021년 2월 16일
Start buy defining the function...
fnF=@(x)x.^2 + x - 10;
Then you have to evaluate the function over whatever range of x you're interested in before doing differences of any sort.
wenchong chen
wenchong chen 2021년 2월 19일
I only got how to find slope for a point, how to find slop for (-1 to 1) in finite difference approximation?

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

답변 (1개)

Shubham Khatri
Shubham Khatri 2021년 2월 21일
Hello,
I have used forward finite difference approximation to design the following code for the purpose.
h=0.1; % step's size
N=10; % number of steps
y(1)=-10;
for n=1:20
y(n+1)= y(n)+h*(4*y(n) + 41)^(0.5);
end
x = -1:0.1:1.1;
plot(x,y);
Hope it helps

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by