How can i solve the error Mupadex?

%Dears
%How can i fix it?
a=-1;
b=2;
n=50;
syms x
f(x)=(x-1)^2+3;
fib=zeros(1,n);
fib(1)=1;
fib(2)=1;
for k=2:n-1
fib(k+1)=fib(k)+fib(k-1);
end
for i=1:n-1
r=fib(n-i)/fib(n+1-i);
c=a+(b-a)*r;
if f(c)>=1.6331e+308
c=0.95*c;
end
d=a+(b-a)*(1-r);
if f(d)>=1.6331e+308
d=0.95*d;
end
h(i)=f(c);
g(i)=f(d);
if f(c)>f(d)
b=c;
else
a=d;
end
end
myans=min(f(c),f(d));
myerrorh=h(n)-h(n-1)
myerrorg=g(n)-g(n-1)
Error in MuPAD command: Index exceeds matrix dimensions.
Error in sym/subsref (line 687)
B = mupadmex('symobj::subsref',A.s,inds{:});

댓글 수: 1

Christiaan
Christiaan 2015년 3월 10일
편집: Christiaan 2015년 3월 10일
Dear Amir,
In the last loop, the variable i goes from i=1 to i=n-1 (n=49) Therefore the vectors h and g have a length of 49.
However if you call h(n), this is not possible since h only a length of 49. (n=50)
To solve this, please provide some information what you would like to do with the function f(x) and the variables 'a' and 'b'.
Kind regards, Christiaan

댓글을 달려면 로그인하십시오.

답변 (0개)

질문:

2015년 3월 8일

편집:

2015년 3월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by