You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old January 24th, 2023, 06:25 PM   #1
adam_lhadi
Member
Algeria

adam_lhadi is offline
 
Join Date: Feb 2022
Location: algeria
Posts: 40
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
Attached Images
File Type: png jjjjjjj.PNG (226.3 KB, 67 views)
  Reply With Quote
Old January 24th, 2023, 06:37 PM   #2
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 6,211
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 (∞).
vi) Hakuna matata.
  Reply With Quote
Old January 24th, 2023, 06:44 PM   #3
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 6,211
Another option, that might work would be
Code:
"1".Expenential_resault := ("1".Expenential_cof) ** REAL_TO_INT("1".linear_Rows - 1));
Although I don't know offhand what the equivalent is in SCL for that REAL_TO_INT function.
__________________
_
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 (∞).
vi) Hakuna matata.
  Reply With Quote
Old January 24th, 2023, 09:54 PM   #4
MaxK
Member
Czech_Republic

MaxK is offline
 
Join Date: Jul 2022
Location: FrozenHell
Posts: 89
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
  Reply With Quote
Old January 25th, 2023, 06:05 AM   #5
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 6,467
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.
Attached Images
File Type: jpg eno.jpg (95.5 KB, 42 views)
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
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 03:09 AM
Micrologix 1400 Fault 0052H caleno LIVE PLC Questions And Answers 15 March 15th, 2018 09:42 AM
what is "I" in pid ? Farid LIVE PLC Questions And Answers 47 October 21st, 2015 12:25 AM
Omron Cj1m glenncovington LIVE PLC Questions And Answers 10 March 7th, 2012 07:01 PM
PID help needed SLaubach LIVE PLC Questions And Answers 23 December 8th, 2011 02:49 PM


All times are GMT -4. The time now is 06:24 PM.


.