Borrar filtros
Borrar filtros

why is this code showing zero for all equations??

3 visualizaciones (últimos 30 días)
Muhammad Adeel Ahsan Awan
Muhammad Adeel Ahsan Awan el 23 de Jun. de 2019
Editada: KALYAN ACHARJYA el 23 de Jun. de 2019
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])

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 23 de Jun. de 2019
Editada: KALYAN ACHARJYA el 23 de Jun. de 2019
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!

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by