IF with 2 conditions in 4 loops

IF with 2 conditions in 4 loops - IF with 2 conditions in 4 loops - Messages

#1 Posted: 6/11/2023 10:38:01 AM
m4xx4mx3

m4xx4mx3

0 likes in 5 posts.

Group: User

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....
---


Screenshot 2023-06-11 152517.png
#2 Posted: 6/11/2023 3:39:23 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

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.
#3 Posted: 6/12/2023 6:42:22 AM
m4xx4mx3

m4xx4mx3

0 likes in 5 posts.

Group: User

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.
#4 Posted: 6/12/2023 8:41:14 AM
Davide Carpi

Davide Carpi

1417 likes in 2873 posts.

Group: Moderator

Like this?

2023-06-12 13_45_03-SMath Solver - [if_4.sm_].png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#5 Posted: 6/12/2023 4:54:16 PM
m4xx4mx3

m4xx4mx3

0 likes in 5 posts.

Group: User

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.
#6 Posted: 6/12/2023 5:24:24 PM
m4xx4mx3

m4xx4mx3

0 likes in 5 posts.

Group: User

Hello againe,

maybe this helps more.

Screenshot 2023-06-12 221852.png

So i took a screenshot.
as you see in this variant.

even if Fx,R and Fy,R are negative. The Loop "uses" the formular with +180° and i dont know why.

many thanks for your help and support
#7 Posted: 6/12/2023 5:33:14 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

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).
atan2.png




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
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

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.

Clipboard01.png

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

Clipboard02.png

notas.sm (11 KiB) downloaded 44 time(s).

Best regards
Alvaro
#9 Posted: 6/13/2023 12:22:46 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

Wrote

Wrote

I hope you understand the project and can help.


Piece wise works, but sanity check.
Cheers ...Jean.

atan(x,y).PNG



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.

Clipboard01.png

Alvaro.
1 users liked this post
#10 Posted: 6/13/2023 12:38:02 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

Wrote

... make it convivial.

Convivial.PNG



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

Clipboard01.png

Best regards.
Alvaro.
#11 Posted: 6/13/2023 4:59:38 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

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
CBG

CBG

77 likes in 312 posts.

Group: User

Hello

I think it could be something like this, using the "case" function.

Angulos.png

Equation_degree.sm (10 KiB) downloaded 58 time(s).


Best Regards


Carlos
#13 Posted: 6/14/2023 7:43:09 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... generalized algo style command line.

AlgoStyle.PNG
#14 Posted: 6/14/2023 10:23:20 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

Wrote

... generalized algo style command line.

AlgoStyle.PNG



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
overlord 6/14/2023 10:51:00 AM, NDTM Amarasekera 6/14/2023 11:38:00 AM
#15 Posted: 6/14/2023 11:52:32 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

... generalized algo style command line.

AlgoStyle.PNG



The tangent of the slope angle of a line is rise over run, not vice versa. So you have to define Quick(x,y) as atan(y/x).


Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#16 Posted: 6/14/2023 12:44:05 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

Thus, 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
overlord

overlord

554 likes in 1333 posts.

Group: Moderator

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.
#18 Posted: 6/14/2023 4:05:23 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

Wrote

Wrote

Thus, 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?

Clipboard01.png

Best regards.
Alvaro
#19 Posted: 6/14/2023 4:53:07 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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?


The correct value is Smath code for Smath projects.
Take care Alvaro ... Jean.

#20 Posted: 6/14/2023 4:57:38 PM
overlord

overlord

554 likes in 1333 posts.

Group: Moderator

Wrote

The 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 New Posts
  • No New Posts No New Posts