How can i solve the error Mupadex?

3 views (last 30 days)
Amir Arshia
Amir Arshia on 8 Mar 2015
Edited: Christiaan on 10 Mar 2015
%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 Comment
Christiaan
Christiaan on 10 Mar 2015
Edited: Christiaan on 10 Mar 2015
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

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!