Message Boards Message Boards

[✓] Avoid problem with IF?

GROUPS:

Good morning, sorry to bother you and take away some of your time, but I wanted to ask you for help with a problem I have with the IF command. Here is the algorithm of the program I am trying to perform:

 l = {{p ^ 2, 85, 74}, {12, 96, 75}, {12, 74, 95}};
Det [l]
a = Variables [Det [l]]
b = Extract [a, 1]
If [b == p, "YES", "NO"]

 -39936 + 3570 p ^ 2

 {p}

 p

"YES"

l = {{q ^ 2, 85, 74}, {12, 96, 75}, {12, 74, 95}};
Det [l]
a = Variables [Det [l]]
b = Extract [a, 1]
If [b == p, "YES", "NO"]

-39936 + 3570 q ^ 2

{q}

q

If [q == p, "YES", "NO"]

If the condition is fulfilled it shows YES that is what I want, but if the condition is not fulfilled it does not show me "NO" but it shows If [b == p, "YES", "NO"] as text, please help me with this problem I would be very grateful. Thank you so much for your help.

POSTED BY: Miguel Saldias
Answer
16 days ago

Try with If[b === p, "YES", "NO"]. Written as b == p it is an equation, not an identity test.

POSTED BY: Gianluca Gorni
Answer
16 days ago

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

The rules explain how to format your code properly. If you do not format code, it may become corrupted and useless to other members. Please EDIT your posts and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

enter image description here

POSTED BY: Moderation Team
Answer
16 days ago

Group Abstract Group Abstract