IF with 2 conditions in 4 loops

IF with 2 conditions in 4 loops - IF with 2 conditions in 4 loops - Сообщения

#1 Опубликовано: 11.06.2023 10:38:01
m4xx4mx3

m4xx4mx3

0 сообщений из 5 понравились пользователям.

Группа: 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 Опубликовано: 11.06.2023 15:39:23
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1675 понравились пользователям.

Группа: 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 Опубликовано: 12.06.2023 06:42:22
m4xx4mx3

m4xx4mx3

0 сообщений из 5 понравились пользователям.

Группа: 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 Опубликовано: 12.06.2023 08:41:14
Davide Carpi

Davide Carpi

1417 сообщений из 2873 понравились пользователям.

Группа: 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 Опубликовано: 12.06.2023 16:54:16
m4xx4mx3

m4xx4mx3

0 сообщений из 5 понравились пользователям.

Группа: 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 Опубликовано: 12.06.2023 17:24:24
m4xx4mx3

m4xx4mx3

0 сообщений из 5 понравились пользователям.

Группа: 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 Опубликовано: 12.06.2023 17:33:14
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: 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 КиБ) скачан 46 раз(а).
atan2.png




Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#8 Опубликовано: 13.06.2023 00:17:32
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1675 понравились пользователям.

Группа: 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 КиБ) скачан 46 раз(а).

Best regards
Alvaro
#9 Опубликовано: 13.06.2023 00:22:46
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1675 понравились пользователям.

Группа: 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 пользователям понравился этот пост
#10 Опубликовано: 13.06.2023 12:38:02
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1675 понравились пользователям.

Группа: 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 Опубликовано: 13.06.2023 16:59:38
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1675 понравились пользователям.

Группа: 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 Опубликовано: 13.06.2023 20:03:46
CBG

CBG

77 сообщений из 312 понравились пользователям.

Группа: User

Hello

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

Angulos.png

Equation_degree.sm (10 КиБ) скачан 58 раз(а).


Best Regards


Carlos
#13 Опубликовано: 14.06.2023 07:43:09
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... generalized algo style command line.

AlgoStyle.PNG
#14 Опубликовано: 14.06.2023 10:23:20
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1675 понравились пользователям.

Группа: 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 пользователям понравился этот пост
overlord 14.06.2023 10:51:00, NDTM Amarasekera 14.06.2023 11:38:00
#15 Опубликовано: 14.06.2023 11:52:32
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: 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 Опубликовано: 14.06.2023 12:44:05
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 14.06.2023 13:30:21
overlord

overlord

554 сообщений из 1333 понравились пользователям.

Группа: 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 Опубликовано: 14.06.2023 16:05:23
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1675 понравились пользователям.

Группа: 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 Опубликовано: 14.06.2023 16:53:07
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 14.06.2023 16:57:38
overlord

overlord

554 сообщений из 1333 понравились пользователям.

Группа: 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 пользователям понравился этот пост
Alvaro Diaz Falconi 14.06.2023 19:23:00
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений