The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Vectorizing the "fzero" function
Replies: 1   Last Post: Oct 31, 2010 2:49 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Abed Alnaif

Posts: 13
Registered: 10/21/08
Vectorizing the "fzero" function
Posted: Oct 31, 2010 2:23 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


I am trying to vectorize Matlab's "fzero" function. This is best explained by an example:

From the code below, I am expecting the output: x = [1 2]. Instead, I am returned the error shown below.

My code is:
function fzero_test
clear all;

function g = myfun(x, a)
g = x.^2 - a;

a = [1 4];

x = fzero(@(x) myfun(x,a), [0 10])

The returned error is:
??? Operands to the || and && operators must be convertible to logical
scalar values.

Error in ==> fzero at 449
while fb ~= 0 && a ~= b

Error in ==> fzero_test at 10
x = fzero(@(x) myfun(x,a), [0 10])

Any help is greatly appreciated! Thanks!

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.