Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!feeds.phibee-telecom.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!gegeweb.org!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Looping with a function
Date: Wed, 29 Feb 2012 06:47:27 -0600
Organization: Aioe.org NNTP Server
Lines: 75
Message-ID: <jil6p1$auo$1@speranza.aioe.org>
References: <jil1dt$b4p$1@newscl01ah.mathworks.com> <jil4pn$5tm$1@speranza.aioe.org> <jil59i$lu3$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: 2Fo2VtEyMcu+SXbR4CvkDA.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:759360

On 2/29/2012 6:22 AM, Michael Boyd wrote:
>
> Ok,
>
> I want to use this piece of code:
>
>   x=fzero(@closedcrank,[pi 2*pi])
>
> To return 30 different values, one for each of the different values of 'phase' in the function. The values of phase are 1:30.
>
> I have little or no programming skills!
>
> I am unsure how to achieve this.
>
> Mike

fzeros function has to to return a scalar.
and do not use 'l' as variable name, as it looks like the
digit one '1'. use upper case L is you must use 'l' to
make it easier to read.


If I understand what you want, may this below will do it

----------------------------
a = 13.5;
L = 48;

phase = (1:30)*pi/180;
f     = @(crank,phi) a*cos(crank-phi)+(L^2-a^2*sin(crank-phi).^2).^0.5-40;

roots = zeros(length(phase),1);

for i = 1:length(phase)
     phi      = phase(i);
     roots(i) = fzero(@(x) f(x,phi),0,[pi 2*pi]);
end
------------------------------

roots =

    -2.0575
    -2.0401
    -2.0226
    -2.0052
    -1.9877
    -1.9703
    -1.9528
    -1.9354
    -1.9179
    -1.9005
    -1.8830
    -1.8656
    -1.8481
    -1.8306
    -1.8132
    -1.7957
    -1.7783
    -1.7608
    -1.7434
    -1.7259
    -1.7085
    -1.6910
    -1.6736
    -1.6561
    -1.6387
    -1.6212
    -1.6038
    -1.5863
    -1.5688
    -1.5514

EDU>>

--Nasser