|
"Nasser M. Abbasi" <nma@12000.org> wrote in message <jil4pn$5tm$1@speranza.aioe.org>...
> On 2/29/2012 5:16 AM, Michael Boyd wrote:
> > Hey guys,
> >
> > was wondering if anyone could help with this simple issue.
> >
> > I have a function;
> >
> > function [IN]=closedcrank(crank)
> > for phase=(1:30)*pi/180;
> > a=13.5;
> > l=48;
> > IN=a*cos(crank-phase)+(l^2-a^2*sin(crank-phase).^2).^0.5-40;
> > end
> > end
> >
>
> That is not a good way to program a loop.
>
> a loop should only iterate over discrete set of values only.
>
> I know, matlab and other loose dynamic languages makes it
> easy to develop bad programming habits.
>
> (and why do you put a ";" after the for=...; )
>
>
> > I want to find the values of 'crank' where the IN is zero.
> >
> > so I am using ;
> >
> > x=fzero(@closedcrank,[pi 2*pi])
> >
> > However, I want matlab to give me values for 'crank' over the varying values of phase.
> >It only gives one value, not the 30 I want.
> >
> > Any help is appreciated!
> >
> > Thanks,
> >
> > Mike
>
> I have no idea what you are doing in your loop in the
> above function. You loop but I do not see an accumulation
> in the loop.
>
> You doing something like
>
> for i=1:100
> X=i^2
> end
>
> So, in the end of the loop, only one value is returned.
> Are you sure you want a loop?
>
> --Nasser
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
|