positive index error in matlab
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
shobi swaminathan
el 25 de En. de 2014
Comentada: shobi swaminathan
el 26 de En. de 2014
clc;
clear all;
R=3;
beta=8;
x1=1:1:10;
for x=1:length(x1)
x=round(x);
f(x)=1-(exp(-((2^(R))-1)/x)^(beta/2));
df(x)=(beta/2)*(((2^R)-1)^beta)*(x^(-(beta+1)))*(exp(-((2^(R))-1)/x)^(beta/2));
format compact
disp(' iterate x f(x) est. error ')
for n = 0:5
s =( f(x)/df(x));
sprintf(' %2d %2.10f %2.10f % 2.10f \n', n,x,f(x),s)
x = x-s;
end
end
error is:
Attempted to access f(-62718.3); index must be a positive integer or logical.
Error in newton (line 15)
s =( f(x)/df(x));
plzz suggest a solution
0 comentarios
Respuesta aceptada
Amit
el 25 de En. de 2014
In MATLAB f(x) usage is to (if f is a matrix) access the xth element in the matrix. And Here thats why you're getting this error.
2 comentarios
Amit
el 25 de En. de 2014
If I was you, I'd do something like this:
R=3;
beta=8;
x1=1:1:10;
x = 1; % Intial value of x
for n=1:length(x1)
f=1-(exp(-((2^(R))-1)/x)^(beta/2));
df=(beta/2)*(((2^R)-1)^beta)*(x^(-(beta+1)))*(exp(-((2^(R))-1)/x)^(beta/2));
format compact
disp(' iterate x f(x) est. error ')
% for n = 0:5
s =( f/df);
disp(sprintf(' %2d %2.10f %2.10f % 2.10f \n', n,x,f,s));
x = x-s;
%end
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!