|
dpb <none@non.net> wrote in message <iusggi$mfh$1@speranza.aioe.org>...
> On 7/4/2011 8:00 AM, Sunipa Som wrote:
> > Hallo,
> > I have to calculate the value of q1(below). Condition is if q1>50 then
> > q1=50.
> > Now I am looping in this way
> > del=3*10^(3);
> > beta=0.25;
> > M=10;
> > e0=601.04;
> > for j= 1:50
> > q1=floor((sqrt(M)*((beta/2)-sqrt(((sqrt(j/M)-(beta/2)).^2)+(del/(e0))))).^2);
> > if q1>50
> > q1=50;
> > else
> > q1=floor((sqrt(M)*((beta/2)-sqrt(((sqrt(j/M)-(beta/2)).^2)+(del/(e0))))).^2);
> > end
> > end
> >
> > But then it is giving 9 values of q1 which are upto 50 but I need 50
> > values of q1. How can i di this?
> > Thank you
> > Som
>
> As you've written it, you're overwriting the one value of q1 each loop
> anyway...and unless my eyes fail me the second definition is the same as
> the first. Use Matlab vector facilities
>
> >> e0=601.04;
> >> M=10;
> >> sqrM=sqrt(M);
> >> beta=0.25;
> >> del=3000;
> >> j=1:10;
> >>
> q1=floor((sqrM*((beta/2)-sqrt(((sqrt(j./M)-(beta/2)).^2)+(del/(e0))))).^2);
> >> q1
> q1 =
> 44 45 46 46 47 48 49 50 50 51
> >> >> q1=min(q1,50)
> q1 =
> 44 45 46 46 47 48 49 50 50 50
> >
>
> I shortened the j vector to 10 for brevity; same principle holds.
>
> BTW, as a stylistic comment, don't use "j" as another variable in
> Matlab--it and "i" are defined as the sqrt(-1) and overwriting those
> will come to bite at some point when dealing w/ complex values. Better
> to build the habit early in acquaintance w/ Matlab.
>
> --
Thank you for your help. Now I got it.
With Regards,
Som
|