Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming help

Status
Not open for further replies.

htxcrew

Automotive
May 17, 2005
2
I have a equation with multiple answers but I just want one solution. E.g a quadratic equation and I only want the positive result. How can I do that??
 
Replies continue below

Recommended for you

Consider using conditional statement or loops such "for", "while", if, <, > etc.

Other option is obtain the solution with in a regionm contained by equation.
 
Given that some quadratics will have two positive answers, and others have none, its a bit hard to answer, but something like

biggest:max(ans1,ans2)

would sort of work.

Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
The solution to a quadratic will be a vector, so using the max function as suggested by Greg should be easy. For instance:

y=23·x+42·x²-32

solve for x

x=-23/84+((5905+168·y)^(1/2))/84
and -23/84-((5905+168·y)^(1/2))/84

with y=456, x evaluates to a vector with elements 3.146 and -3.693. max(x)=3.146
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor