Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski 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
Joined
May 17, 2005
Messages
2
Location
DK
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??
 
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

Back
Top