필터 지우기
필터 지우기

why is this code showing zero for all equations??

조회 수: 3 (최근 30일)
Muhammad Adeel Ahsan Awan
Muhammad Adeel Ahsan Awan 2019년 6월 23일
편집: KALYAN ACHARJYA 2019년 6월 23일
disp('Enter all values in row vector ');
x=input('Enter the values of x=');
y=input('Enter the values of function at x f(x)=');
val=input('Enter the value of x at which derivative is to be calculated=');
i=find(x==val);
fd=[y(i+1)-y(i)]/[x(i+1)-x(i)];
cd=[y(i+1)-y(i-1)]/[x(i+1)-x(i-1)];
bd=[y(i)-y(i-1)]/[x(i)-x(i-1)];
disp('Following are the Difference Derivatives')
disp(' FDD CDD BDD')
disp([fd cd bd])

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 23일
편집: KALYAN ACHARJYA 2019년 6월 23일
Enter the val value such that it must contain in x, then only following give some non zero value
i=find(x==val);
Other wise If you enter like as follows
Enter all values in row vector
Enter the values of x=[1 2 3 4]
Enter the values of function at x f(x)=[1 2 4 5]
Enter the value of x at which derivative is to be calculated=6
Now form the next statemnet
i=find(x==val);
Find in x, which equal to 6, actually 6 is not there, hence it return null
>> whos i
Name Size Bytes Class Attributes
i 1x0 0 double
which leads to zero in the equations.
Following gives non zero result, where I have choose val=2, which is part of x vector.
Enter all values in row vector
Enter the values of x=[1 2 3 4]
Enter the values of function at x f(x)=[1 2 4 5]
Enter the value of x at which derivative is to be calculated=2
Following are the Difference Derivatives
FDD CDD BDD
2.0000 1.5000 1.0000
Hope it Helps!

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by