Mathe equation error

adam_lhadi

Member
Join Date
Feb 2022
Location
algeria
Posts
59
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

jjjjjjj.PNG
 
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));
 
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.
 
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
 
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.

eno.jpg
 

Similar Topics

Hi folks, I am upgrading a SLC to a ControlLogix platform. The goal of the project isn't simply to get the same program to run on different...
Replies
7
Views
2,807
Hey All! Using the HSC:0 for an unwind. Not high speed or anything. 50 PPR at fastest 800 FPM.using this math pulse count per second / 50 the...
Replies
9
Views
2,513
Any one know iso 1438 open channel Rectangular notch discharge equation
Replies
1
Views
1,575
Hi all, Have a job where we're using peristaltic pumps to dose CL2 for wastewater, pretty standard 4-20mA flow pacing signal being used, no PID...
Replies
3
Views
1,695
Hello, I've been told that this is the way i need to calculate airflow from a DP transmitter. I am far from a math genius and trying to find out...
Replies
6
Views
3,068
Back
Top Bottom