positive index error in matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Amit
2014년 1월 25일
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
Amit
2014년 1월 25일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!