Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Looping with a function
Date: Wed, 29 Feb 2012 13:55:12 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 78
Message-ID: <jilao0$9sa$1@newscl01ah.mathworks.com>
References: <jil1dt$b4p$1@newscl01ah.mathworks.com> <jil4pn$5tm$1@speranza.aioe.org> <jil59i$lu3$1@newscl01ah.mathworks.com> <jil6p1$auo$1@speranza.aioe.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1330523712 10122 172.30.248.35 (29 Feb 2012 13:55:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 29 Feb 2012 13:55:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3350677
Xref: news.mathworks.com comp.soft-sys.matlab:759369

"Nasser M. Abbasi" <nma@12000.org> wrote in message <jil6p1$auo$1@speranza.aioe.org>...
> 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

Thank you very much!