f

Matlab programming to find minimum help!?

```What I need to is to figure out how to find the lowest value for L when Tac and Tab are both <2000.

I've tried directing them into an array, and trying to find the minimum of the array, but I can't seem to get the array to only take values where tac and tab are both <2000. It simply takes all the values and gives min(L) = 3.

L=3:0.1:6.7;
th = acos((45-L.^2)/36);
ph = asin((6*sin(th))./L);

j=1;

Tab = 2000./(sin(th)+cos(th).*tan(ph));
if Tab<2000 then
Tac = (2000.*cos(th))./(sin(th)+cos(th).*tan(ph));
if Tac<2000 then
ARRAY(j)=(L,Tab,Tac)
j=j+1;
end
end

plot(L,Tab,'m',L,Tac,'b'),xlabel('Length of AC'),ylabel('Tension'),title('Tension Plot');
legend('Tab','Tac');

How do I put everything in a while loop where L starts as 3 and then increases by 0.1 until it get 6.7 ...  HELP!!
```
 0
11/30/2008 1:49:02 AM
comp.soft-sys.matlab 211266 articles. 19 followers. lunamoonmoon (257) is leader.

2 Replies
654 Views

Similar Articles

[PageSpeed] 49

```"Michael Elite" <elitemichael@yahoo.com> wrote in message <ggsree\$3is\$1@fred.mathworks.com>...
> What I need to is to figure out how to find the lowest value for L when Tac and Tab are both <2000.
>
> I've tried directing them into an array, and trying to find the minimum of the array, but I can't seem to get the array to only take values where tac and tab are both <2000. It simply takes all the values and gives min(L) = 3.
>
>
> L=3:0.1:6.7;
> th = acos((45-L.^2)/36);
> ph = asin((6*sin(th))./L);
>
> j=1;
>
> Tab = 2000./(sin(th)+cos(th).*tan(ph));
> if Tab<2000 then
> Tac = (2000.*cos(th))./(sin(th)+cos(th).*tan(ph));
> if Tac<2000 then
> ARRAY(j)=(L,Tab,Tac)
> j=j+1;
> end
> end
>
> plot(L,Tab,'m',L,Tac,'b'),xlabel('Length of AC'),ylabel('Tension'),title('Tension Plot');
> legend('Tab','Tac');
>
> How do I put everything in a while loop where L starts as 3 and then increases by 0.1 until it get 6.7 ...  HELP!!

It seems like you don't necessarily need to use a WHILE or FOR loop.  With a conditional like this, I think it is easier to understand using conditionals.

L=3:0.1:6.7;
th = acos((45-L.^2)/36);
ph = asin((6*sin(th))./L);

Tab = 2000./(sin(th)+cos(th).*tan(ph));
Tac = (2000.*cos(th))./(sin(th)+cos(th).*tan(ph));

isTabConditional = ( Tab < 2000 );
isTacConditional = ( Tac < 2000 );

Array = L( isTabConditional & isTacConditional );

plot(L,Tab,'m',L,Tac,'b'),xlabel('Length of AC'),ylabel('Tension'),title('Tension Plot');
legend('Tab','Tac');

[mOfArray, mIdxOfArray] = min(Array);

fprintf(1, 'Min of Array is %d, Min index of Array is %d\n', ...
mOfArray, mIdxOfArray);
```
 0
ryano1 (46)
11/30/2008 2:25:03 AM
```L=3:0.1:6.7;
th = acos((45-L.^2)/36);
ph = asin((6*sin(th))./L);
Tab = 2000./(sin(th)+cos(th).*tan(ph));
Tac = (2000.*cos(th))./((sin(th)+cos(th).*tan(ph)));

j=1;
while Tab(j)>=2000 | Tac(j)>=2000
j=j+1;
end
L(j)

&#22519;&#34892;&#32080;&#26524;

L =

3.4000

>> j

j =

5

```
 0
12/2/2008 6:56:01 AM