Thread Subject: Matlab programming to find minimum help!?

Subject: Matlab programming to find minimum help!?

From: Michael Elite

Date: 30 Nov, 2008 01:49:02

Message: 1 of 3

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!!

Subject: Matlab programming to find minimum help!?

From: Ryan Ollos

Date: 30 Nov, 2008 02:25:03

Message: 2 of 3

"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);

Subject: Matlab programming to find minimum help!?

From: Michael Elite

Date: 2 Dec, 2008 06:56:01

Message: 3 of 3

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)






執行結果



L =



    3.4000



>> j



j =



     5

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com