Filter löschen
Filter löschen

positive index error in matlab

1 Ansicht (letzte 30 Tage)
shobi swaminathan
shobi swaminathan am 25 Jan. 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

Akzeptierte Antwort

Amit
Amit am 25 Jan. 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 Kommentare
Amit
Amit am 25 Jan. 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
shobi swaminathan
shobi swaminathan am 26 Jan. 2014
Thanks alot..dis code is working

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by