i am trying to find omega using while

I need to determine omega.
I came so far to think that i need a while loop to do so but I get an error, so want to check my syntax is correct.
%Exercise 3
m=[3.3e2 3.3719e2 2.7564e2 2.2902e2 1.9140e2 1.6692e2 1.5947e2...
8.4519e1 4.7877e1 3.3029e1 2.5357e1 1.9990e1]; %constants given
py_guess=zeros(1,length(x));
pz_guess=zeros(1,length(x));
py_guess(2:length(x))=100;
pz_guess(2:length(x))=100;
tolerance=0.001;
while
omega=sqrt(pz_guess(12)/(u_zGuess(12)*m(12)))
if
omega_old=omega
break
else
[u_yGuess,u_zGuess]=UyUzCalcGuess(x,py_guess,pz_guess,EI1,EI2,B);
end
end
my function runs as it should.
Assignment3
Error: File: Assignment3.m Line: 210 Column:
6
Expression or statement is incomplete or
incorrect.

 Accepted Answer

The syntax for while is
while CONDITION
...
end
If you want your loop to run until you break, then use
while true
...
end

5 Comments

i understand what you wrote but i am unsure of my syntax.
I have:
omega=0;
omega_old=0;
while omega_old<omega
[u_yGuess,u_zGuess]=UyUzCalcGuess(x,py_guess,pz_guess,EI1,EI2,B)
omega=sqrt((pz_guess(12)/(u_zGuess(12)*m(12))));
omega=omega_old
pz_guess=omega^2*m*(u_zGuess/(sqrt((u_zGuess(12)^2)+(u_yGuess(12)^2))));
Py_guess=omega^2*m*(u_yGuess/(sqrt((u_zGuess(12)^2)+(u_yGuess(12)^2))));
end
what i am trying to achieve is to get omega to converge with the formulas in my loop. but when i run it it just gives omega=0
You start omega and omega_old at the same value. 0<0 is false, so your body of your while will never be executed. You should initialize omega_old to -infinity
Caution: your code calculates a new value for omega and then promptly assigns omega_old to omega instead, and your code never changes omega_old
omega_old=0;
omega=0;
while omega_old<=omega || omega_old==0 || omega==0
[u_yGuess,u_zGuess]=UyUzCalcGuess(x,py_guess,pz_guess,EI1,EI2,B)
omega_old=sqrt((pz_guess(12)/(u_zGuess(12)*m(12))));
pz_guess=omega^2*m.*(u_zGuess/(sqrt((u_zGuess(12)^2)+(u_yGuess(12)^2))));
Py_guess=omega^2*m.*(u_yGuess/(sqrt((u_zGuess(12)^2)+(u_yGuess(12)^2))));
omega_old=omega
end
This is what i have so far but it is stuck in an inifite loop.
I need help how to resolve this and find the frequency omega.
You have
omega_old=sqrt((pz_guess(12)/(u_zGuess(12)*m(12))));
which assigns to omega_old. Then you have
omega_old=omega
which assigns a different value to omega_old . Meanwhile, you have not assigned a value to omega .
omega_old = -inf;
omega = 0;
while omega_old <= omega
omega_old = omega;
omega = ....
end
thank you! it is running now and i am getting values, however it is not converging before i get an error with matrix exceeds index

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!