positive index error in matlab
2 次查看(过去 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!