IF with 2 conditions in 4 loops - IF with 2 conditions in 4 loops - Messages
#1 Posted: 6/11/2023 10:38:01 AM
Hey, ich versuche eine If schleife zu schreiben, die von 2 Werten abhängt und je nachdem ob die Kombination "positiv Positiv" , "Positiv negativ" oder "Negativ negativ" ist soll ein anderer Wert mit einem andreen Beiwert berechnet werden...
---
MOD: Translated with DeepL
Hey, I'm trying to write an If loop that depends on 2 values and depending on whether the combination is "positive positive" , "positive negative" or "negative negative" a different value with a different coefficient should be calculated....
---

---
MOD: Translated with DeepL
Hey, I'm trying to write an If loop that depends on 2 values and depending on whether the combination is "positive positive" , "positive negative" or "negative negative" a different value with a different coefficient should be calculated....
---
#2 Posted: 6/11/2023 3:39:23 PM
Hi. While loops never stop, since the criterion to stop them, if it is met the first time, will always be met by not modifying the condition that caused it to be executed. Perhaps what you require is simply nesting if conditions.
Best regards.
Alvaro.
Best regards.
Alvaro.
#3 Posted: 6/12/2023 6:42:22 AM
Thank you very much,
can you explain how i can add 2 conditions (like in my case Fx,R and Fy,R) to the first IF. Since both need to be required to select the right "Math-formula"
Thanks in advance.
can you explain how i can add 2 conditions (like in my case Fx,R and Fy,R) to the first IF. Since both need to be required to select the right "Math-formula"
Thanks in advance.
#4 Posted: 6/12/2023 8:41:14 AM
#5 Posted: 6/12/2023 4:54:16 PM
Since i don't understand how i can ad my SMath Solver I try to explain it more.
I have a Task. The first stepps are allready done.
My last step is:
Lets say i have
X:10
and Y:6.
I got a Formular to solve a angle:
a°=atan(x/y)
BUT if x or y is Negative my formular is:
a°=atan(x/y)+180°
and if x and y is negative my formular is:
a°=atan(x/y)+360°
In conclusion my problem is i don't understand how to say
as soon as 1 of these conditions are suffused --> solve the formular for a° and end the loop.
Like
IF X & Y is positive solve:
a°=atan(x/y)
IF X is positive and Y is negative solve:
a°=atan(x/y)+180°
IF X is negative and Y is positive solve:
a°=atan(x/y)+180°
IF X & Y is negative solve:
a°=atan(x/y)+360°
I hope you underdstand me and can help me.
Sorry for my bad english
thanks in advance
I tried your advice with 2 IF in once but i don't undersand how to "end/close" the loop.
I have a Task. The first stepps are allready done.
My last step is:
Lets say i have
X:10
and Y:6.
I got a Formular to solve a angle:
a°=atan(x/y)
BUT if x or y is Negative my formular is:
a°=atan(x/y)+180°
and if x and y is negative my formular is:
a°=atan(x/y)+360°
In conclusion my problem is i don't understand how to say
as soon as 1 of these conditions are suffused --> solve the formular for a° and end the loop.
Like
IF X & Y is positive solve:
a°=atan(x/y)
IF X is positive and Y is negative solve:
a°=atan(x/y)+180°
IF X is negative and Y is positive solve:
a°=atan(x/y)+180°
IF X & Y is negative solve:
a°=atan(x/y)+360°
I hope you underdstand me and can help me.
Sorry for my bad english
thanks in advance
I tried your advice with 2 IF in once but i don't undersand how to "end/close" the loop.
#6 Posted: 6/12/2023 5:24:24 PM
#7 Posted: 6/12/2023 5:33:14 PM
I know that in some textbooks there are weird tables to compute the direction of a vector from it's components, because they use atan(y/x). Yet there are better options:
- two-argument form of atan(), in other programming languages, this is atan2()
- argument of a complex number
- dedicated SMath-function for conversion between rectangular and polar co-ordinates
atan2.sm (4 KiB) downloaded 45 time(s).

- two-argument form of atan(), in other programming languages, this is atan2()
- argument of a complex number
- dedicated SMath-function for conversion between rectangular and polar co-ordinates
atan2.sm (4 KiB) downloaded 45 time(s).
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#8 Posted: 6/13/2023 12:17:32 AM
Wrote...
even if Fx,R and Fy,R are negative. The Loop "uses" the formular with +180° and i dont know why. ...
Hi. What you have is not a loop, it's a series of nested if's. I'm sorry I can't express it in German. That from a conceptual point of view. From a practical point of view, you use the 'line' command in SMath, which simply returns the last value. You need to use a boolean operator, in this case 'and'. You can also use the functions of inequalities indicated in the figure.
As Martin says, physics books have very complicated ways to handle vectors in polar coordinates, which do nothing but complicate everything. To his list could be added the use of functions like this to restrict the value of the angle to a certain interval
notas.sm (11 KiB) downloaded 44 time(s).
Best regards
Alvaro
#9 Posted: 6/13/2023 12:22:46 AM
WroteWroteI hope you understand the project and can help.
Piece wise works, but sanity check.
Cheers ...Jean.![]()
That's wrong, as usual. Conceptually, you don't use break without a while or a for. Otherwise you get an unnecessary error. And to finish embellishing it, you use the units wrong: the conversion between radians and sexagesimal degrees is wrong too.
Alvaro.
1 users liked this post
Вячеслав Мезенцев 6/13/2023 3:07:00 AM
#10 Posted: 6/13/2023 12:38:02 PM
Wrote
atan(-2,-4)=-153.4349 'deg ... so, what's the point to add 2*π/180 to get -151.4349 'deg? Just try to learn something about radians and degrees. The expected value, if the intention is to restrict the angle at the interval 0 ≤ phi < 360 is -153.4349 'deg + 360 'deg = 206.5651 'deg
Best regards.
Alvaro.
#11 Posted: 6/13/2023 4:59:38 PM
Wrote... Add something in radian. ...
So, you don't make (again) a mistake with units. You just shows how to add "something in radian" like 2*π/180 = 2 deg instead the value provided by the user of 360 deg, and π/180 = 1 deg instead 180 deg. Good to know. Excellent example of handling random constants in programming. No one could be confused with that judicious choice of values. "sostenella y no enmendalla"
Best regards.
Alvaro.
#12 Posted: 6/13/2023 8:03:46 PM
Hello
I think it could be something like this, using the "case" function.

Equation_degree.sm (10 KiB) downloaded 58 time(s).
Best Regards
Carlos
I think it could be something like this, using the "case" function.
Equation_degree.sm (10 KiB) downloaded 58 time(s).
Best Regards
Carlos
#13 Posted: 6/14/2023 7:43:09 AM
#14 Posted: 6/14/2023 10:23:20 AM
Wrote
Jean, it seems you keep getting things mixed up. If you took some time to analyze things you might see that the "Originator" (I guess it's m4xx4mx3) uses atan(Fy/Fx), and Martin uses atan(Y;X) or arg(X+ iY) to get the angle of the vector of components (X,Y) ...
Thus, the correct angle of the vector with components (4,2) is 26.5651°, and not 63.4349° as you seem to suggest. Again, "sostenella y no enmendalla".
Best regards.
Alvaro.
2 users liked this post
#15 Posted: 6/14/2023 11:52:32 AM
#16 Posted: 6/14/2023 12:44:05 PM
WroteThus, the correct angle of the vector with components (4,2) is 26.5651°, and not 63.4349°
So, we are three idiots in there ... Carlos, Jean, Smath
as we have same atan(4,2)... 63.4349°
You confused yourself from Mathcad atan2(4,2) = 26.5651°
Revisit the Mathcad definitions & codes.
atan(4/2) = 63.4349°
#17 Posted: 6/14/2023 1:30:21 PM
x=4
y=2
atan(y/x)=26.5651°
atan(y;x)=26.5651°
Owner of post asked for y/x, not x/y.
I can't speak for Carlos.
But for you... yeah, you are an idiot.
y=2
atan(y/x)=26.5651°
atan(y;x)=26.5651°
Owner of post asked for y/x, not x/y.
I can't speak for Carlos.
But for you... yeah, you are an idiot.
#18 Posted: 6/14/2023 4:05:23 PM
WroteWroteThus, the correct angle of the vector with components (4,2) is 26.5651°, and not 63.4349°
So, we are three idiots in there ... Carlos, Jean, Smath
as we have same atan(4,2)... 63.4349°
You confused yourself from Mathcad atan2(4,2) = 26.5651°
Revisit the Mathcad definitions & codes.
atan(4/2) = 63.4349°
If I'm confused and the angle of the vector with components (4,2) is not 26.5651°, could you explain to me what is the correct value, please?
Best regards.
Alvaro
#19 Posted: 6/14/2023 4:53:07 PM
WroteIf I'm confused and the angle of the vector with components (4,2) is not 26.5651°, could you explain to me what is the correct value, please?
The correct value is Smath code for Smath projects.
Take care Alvaro ... Jean.
#20 Posted: 6/14/2023 4:57:38 PM
WroteThe correct value is Smath code for Smath projects.
Take care Alvaro ... Jean.
He has not the answer and not admitting he made a mistake, as usual from Jean.
1 users liked this post
Alvaro Diaz Falconi 6/14/2023 7:23:00 PM
-
New Posts
-
No New Posts