Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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

Hello,

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;
end

a = [1 4];

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


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]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.