×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Simple programing to recognize "negative solution"

## Simple programing to recognize "negative solution"

(OP)
Hi folks!
Somethnig Im trying to do but simply cannot find the solution.
Few questions.

I have an quadriatic equation wich sometimes creates negative number under the root expression.
I would like Mathcad to write an expression when this happens.
I tried doing this with simple programing.
Basicly what I did is add to lines with two conditions:
1st) "NOT AVAILABLE" if .................... (this is where I get lost, how to tell him when you get negative number under the squareroot?)
2nd) "AVAILABLE" otherwise

Is it possible to hide the function (expression) for wich you are finding the solution.
Like in previous egsample X:= two mentioned programing lines
Wich would finaly give X = something
How to hide "X=" so that you only see the result?

When using programing lines is it possible to define two action for one conditions and one action for the second condition?
Egsample if I have equation x-3=0
II"AVAILABE" I
II I if x>0
II"X=5" I
I "Not available" othervise

So basicly if x gives soution >0 I would like Mathcad to report an "AVAILABE" comment and give the solution x=5

Any chance for something like this?
Thank you.
Replies continue below

### RE: Simple programing to recognize "negative solution"

you could do an If statement that checks (a-b) < |a-b| (or whatever is inside your rood) then don't do the root.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.
The plural of anecdote is not "data"

### RE: Simple programing to recognize "negative solution"

(OP)
I dont understand you well
Can you explain a bit more.
Thank you,

(OP)
Think Ive got it

### RE: Simple programing to recognize "negative solution"

This is the MathCad forum right?

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.
The plural of anecdote is not "data"

### RE: Simple programing to recognize "negative solution"

(OP)
Seem that Ive hit another problem.
I have a function called

Using the "root function" I want to find the solution for x1
x1:=root(Nos(x),x,0,h)=

Later in the worksheet I made an simple programing involving the value x1 wich basicly says when to use x1 value and when to not use
it.

But once the x1 value becomes unavailable (its not within the limits "0 and h", negative number under the square root appears) Mathcad simply ignores all other programing statements and just marks the x in RED saying that the variable is not defined.
I tried puting the statments that involves "x1" to the end of the programin line and even used RETURN operation on previous statments but it seems that if the x1 doesnt have some real solution it just blocks the programing line.
Can this programing line somehow work eventhou "x1" doesnt have any solution in defined limits?

### RE: Simple programing to recognize "negative solution"

(OP)
Damn.
Im trying this also with an "on error" statement when the x value is not within the limits but it still doesnt work

### RE: Simple programing to recognize "negative solution"

(OP)
Plase read my previous post more carefuly.
------> "greater then 8"

### RE: Simple programing to recognize "negative solution"

(OP)
Sir,
please do check your statements before you post them and also try using them first with the files I previously attached.
Thank you.

### RE: Simple programing to recognize "negative solution"

(OP)
Yes it work out side the programing line, but how to make it work inside the programing lines (my previous attached file)?
Thats the problem.

(OP)
Solved!
Thanx!

### RE: Simple programing to recognize "negative solution"

(OP)
Hmmmmmmmm...
This is very interesting.
Thank you!
Can plase explain the 1+1 condition in you statement. Why?

### RE: Simple programing to recognize "negative solution"

(OP)
Hi!
Heres the same solution (thanx to you) in another way.
But I dont understand how can MATHCAD calculate z value thats "under 5" if I didnt define the last programing line as "x1"?
Its seems that it went thru the last condition "greater then 5" if root(........)>5" saw that its not valid and anyway calculated the value.
On the other hand if I put 3rd programing statement as "x1" as soon my root equation is not vaild it returns error.

### RE: Simple programing to recognize "negative solution"

It doesn't need to be on the last line, it just needs to have been assigned and not over-written, and it needs to still be running the program.

As in algebra, order of operations is important, with the additional wrinkle that you have the option of ending the program prematurely. So, you have to pay particular attention to what you've commanded in the logical flow of the program. This is what makes programs so difficult to debug and maintain, which is further compounded by the innate lack of debugging tools in Mathcad.

http://files.engineering.com/getfile.aspx?folder=2...

TTFN
FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

### RE: Simple programing to recognize "negative solution"

(OP)
@IRstuff
Thank you very much!
Egsamples you posted where realy helpfull in understanding the importance order when programing with MATHCAD

@rmix22
How did you use these scriptable components?
Insert-> Component-> ???

### RE: Simple programing to recognize "negative solution"

#### Quote (mar2805)

How did you use these scriptable components?
Basically yes. The specific here was copied from another sheet of mine and then the VB code edited to fit your needs.

### RE: Simple programing to recognize "negative solution"

@mar2805: Sorry, I missed your ???'s

It's: Insert/Control/Text Box
then RightClick - Edit script
and off we go using VBScript commands
At last to clean up I chose to Hide Arguments (again RIghtClick)

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!