Why am I getting error: Index must be a positive integer of logical?

1 view (last 30 days)
Attached is the code. It is supposed to use the newton raphson method to find the root of a function. func is the function, dfunc is the derivative of the function, xr is the first "guess" (in this case it is .5), maxit is the maximum iterations to be performed.
The command I enter is: newtonraphson('@x -0.9*x^2 + 1.7*x +2.5', '@x -2*.9*x^2 + 1.7', 5, .01, 50)
but I cannot get back an answer that isn't erroneous.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Sep 2013
You are providing a string as the parameter func, and you have func(xr) inside your code. That is an attempt to subscript the string.
'@x -0.9*x^2 + 1.7*x +2.5' is a string, not a function handle.
Hint:
@(x) -0.9*x^2 + 1.7*x +2.5
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!