IF with 2 conditions in 4 loops

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

#1 Publicado: 11/6/2023 10:38:01
m4xx4mx3

m4xx4mx3

0 me gusta en 5 mensajes.

Grupo: 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 Publicado: 11/6/2023 15:39:23
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: 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 Publicado: 12/6/2023 6:42:22
m4xx4mx3

m4xx4mx3

0 me gusta en 5 mensajes.

Grupo: 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 Publicado: 12/6/2023 8:41:14
Davide Carpi

Davide Carpi

1.443 me gusta en 2.936 mensajes.

Grupo: 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 Publicado: 12/6/2023 16:54:16
m4xx4mx3

m4xx4mx3

0 me gusta en 5 mensajes.

Grupo: 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 Publicado: 12/6/2023 17:24:24
m4xx4mx3

m4xx4mx3

0 me gusta en 5 mensajes.

Grupo: 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 Publicado: 12/6/2023 17:33:14
Martin Kraska

Martin Kraska

1.361 me gusta en 2.275 mensajes.

Grupo: 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,14 KiB) descargado 1294 vez(es).
atan2.png




Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
#8 Publicado: 13/6/2023 0:17:32
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: 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,9 KiB) descargado 1278 vez(es).

Best regards
Alvaro
#9 Publicado: 13/6/2023 0:22:46
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: 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.
A 1 usuarios les gustó este mensaje
#10 Publicado: 13/6/2023 12:38:02
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: 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 Publicado: 13/6/2023 16:59:38
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: 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 Publicado: 13/6/2023 20:03:46
CBG

CBG

78 me gusta en 312 mensajes.

Grupo: User

Hello

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

Angulos.png

Equation_degree.sm (10,67 KiB) descargado 1335 vez(es).


Best Regards


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

Jean Giraud

983 me gusta en 6.866 mensajes.

Grupo: User

... generalized algo style command line.

AlgoStyle.PNG
#14 Publicado: 14/6/2023 10:23:20
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: 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.
A 2 usuarios les gustó este mensaje
overlord 14/6/2023 10:51:00, NDTM Amarasekera 14/6/2023 11:38:00
#15 Publicado: 14/6/2023 11:52:32
Martin Kraska

Martin Kraska

1.361 me gusta en 2.275 mensajes.

Grupo: 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).


Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
#16 Publicado: 14/6/2023 12:44:05
Jean Giraud

Jean Giraud

983 me gusta en 6.866 mensajes.

Grupo: 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 Publicado: 14/6/2023 13:30:21
overlord

overlord

600 me gusta en 1.381 mensajes.

Grupo: 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 Publicado: 14/6/2023 16:05:23
Alvaro

Alvaro

1.139 me gusta en 1.805 mensajes.

Grupo: 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 Publicado: 14/6/2023 16:53:07
Jean Giraud

Jean Giraud

983 me gusta en 6.866 mensajes.

Grupo: 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 Publicado: 14/6/2023 16:57:38
overlord

overlord

600 me gusta en 1.381 mensajes.

Grupo: 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.
A 1 usuarios les gustó este mensaje
Alvaro 14/6/2023 19:23:00
  • Nuevos mensajes
  • Sin mensajes nuevos