![]() ![]() ![]() ![]() ![]() ![]() |
||
![]() |
||
![]() ![]() ![]() ![]() This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
![]() |
![]() |
#1 |
Member
![]() ![]() Join Date: Feb 2022
Location: algeria
Posts: 48
|
Mathe equation error
HI
when using this piece of code "1".Expenential_resault := ("1".Expenential_cof )**(("1".linear_Rows) -1); i get an error (Pic 1) how to fix it the purpose is to get a resault of (+1 -1 +1 -1 +1........) when i change the value manually it works great "1".Expenential_resault := ("1".Expenential_cof )**(1 or 2 or 3... so on) also this code gives me an error "1".Expenential_resault := (-1)**(("1".linear_Rows) -1) using -1 gives an error but declaring a constant in data block with -1 value solve the problem ,so what's the diffrence kind regards |
![]() |
![]() |
#2 |
Lifetime Supporting Member
|
if you change the "(3)" to "(3.0)" in the code that works it will probably fail.
try casting .linear_Rows as an integer. It might work. The other option would be to simply toggle the sign of the result based on the result of of (.linear_Rows MOD 2). e.g. something like this: Code:
"1".Expenential_resault := 1.0 - (2.0 * (("1".linear_Rows - 1) MOD 2.0));
__________________
_ Brian T. Carcich i) Take care of the bits, and the bytes will take care of themselves. ii) There is no software problem that cannot be solved with another layer of indirection. iii) Measurement is hard. iv) I solemnly swear that I am up to no good ![]() v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ![]() vi) Hakuna matata. vii) Bookkeeping. |
![]() |
![]() |
#3 |
Lifetime Supporting Member
|
Another option, that might work would be
Code:
"1".Expenential_resault := ("1".Expenential_cof) ** REAL_TO_INT("1".linear_Rows - 1));
__________________
_ Brian T. Carcich i) Take care of the bits, and the bytes will take care of themselves. ii) There is no software problem that cannot be solved with another layer of indirection. iii) Measurement is hard. iv) I solemnly swear that I am up to no good ![]() v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ![]() vi) Hakuna matata. vii) Bookkeeping. |
![]() |
![]() |
#4 |
Member
![]() ![]() Join Date: Jul 2022
Location: FrozenHell
Posts: 221
|
qNaN. Possibly due to data type mismatch. Finding the problem is not easy.
Easier to use the #2 solution. or "1".Expenential_resault := "1".Expenential_resault * -1 |
![]() |
![]() |
#5 |
Lifetime Supporting Member
![]() ![]() Join Date: Nov 2006
Location: UK
Posts: 6,623
|
If you attempt to use a hard coded negative number in a power operation you will get a compiler error 'negative base specified for power operation'
If you attempt to use a variable that is negative in a power operation you will get a run time error which you test for by checking the ENO variable in SCL.
__________________
S7-300 to 1500 conversions done - email (minus the spam) to spams7conversions@hotmail.com |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
CMMO-ST-C5-1-LKP , FESTO, Error 0x47 Modbus connection with master control | xfr82 | LIVE PLC Questions And Answers | 3 | January 24th, 2019 02:09 AM |
Micrologix 1400 Fault 0052H | caleno | LIVE PLC Questions And Answers | 15 | March 15th, 2018 08:42 AM |
what is "I" in pid ? | Farid | LIVE PLC Questions And Answers | 47 | October 20th, 2015 11:25 PM |
Omron Cj1m | glenncovington | LIVE PLC Questions And Answers | 10 | March 7th, 2012 06:01 PM |
PID help needed | SLaubach | LIVE PLC Questions And Answers | 23 | December 8th, 2011 01:49 PM |