# unknown error

Hi all,
I'm new to Matlab, this is my first matlab question and i used lots of time to solve it but there are some unknown problem that i cant solve.

Question:
Write a MATLAB program, in a m-file that determines the solution of the equation 8-4.5(x-sin x)=0 by using bisection method. The solution should have approximation eorr of less than 0.001%. Create a table that display the value of X1 , Xu , f(x)f(y) and Ea for each iteration of the bisection process.

My current answer after a week of solving:
a = 2
b = 3
for x=a:b
y(a)=8-4.5*(x-sin(x))
y(b)=8-4.5*(x-sin(x))
c = (a + b)/2
for x=c
y(c)=8-4.5*(x-sin(x))
end
if y(c)==0
elseif y(a)*y(c)<0
a=c
end
end
----------------------------------------------
I got this error message,
??? Attempted to access y(2.5); index must be a positive integer or logical.

Error in ==> Untitled at 8
y(c)=8-4.5*(x-sin(x))
------------------------------------
Your help and guidance is appreciated. Thanks

• Hello

The result of this is 2.5, if you want to use this as an matrix index (or array index) it must be an integer. It is possible for you to do a type cast to convert its type.

Example 1:
y(int(c))=8-4.5*(x-sin(x))

int(2.5) = 2

Example 2:
round(2.5) = 3

Or you have to avoid an non-integer result. Negative integers are not allowed.

Kind regards,
Frank.