why is this code showing zero for all equations??
1 次查看(过去 30 天)
显示 更早的评论
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])
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!