How to stop a for loop when it produces complex results
8 views (last 30 days)
Show older comments
I'm using a for loop to alter 2 components of my code a velocity variable (v0) and an angle variable (lambda1). These numbers can combine to produce either real numbers or complex numbers based on their specific values. When they combine to produce a complex number a few lines down the code stops because it involves a function (phi1) that must be real. I'd like to code in a way for it to first check if the combo produces a complex root and if it does, skip back to the loop to change one of the values so that the program doesnt break. Is this possible?
v0 = ; %Du/Tu
phi0 = 0 ;
lambda1 = 30 ;
r1 = sqrt( D^2 + Rsoi^2 - 2*D*Rsoi*cos(lambda1*pi/180) ) ;
Energy0 = v0^2/2 - mu_e/R0 ;
h = R0*v0 ;
v1 = sqrt( 2 * (Energy0 + mu_e/r1)) ;
phi1 = acosd( h / (r1*v1)) ;
1 Comment
Answers (1)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!