Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
In a while loop I am supposed to calculate a value in each iteration.
As an example:
set b=2;
set a=0;
set n=100;
set delta=(b-a)/n;
do while t<b
let W=W+$(t)*$(t);
let t=t+delta;
Loop
For post-processing, I would like to store these values in a field to be able to display them later in a diagram. For the chart I would need dimension and expression.
Dimension=values of t
Expression=values of W
Can someone please help me?
Thank you very much in advance.
With kind regards
try this:
set b=2;
set a=0;
set n=100;
set delta=(b-a)/n;
let W=0;
let t=0;
data:
load null() as t AutoGenerate(0);
do while t<b
let W=W+t*t;
let t=t+$(delta);
concatenate (data) load $(t) as t, $(W) as W AutoGenerate(1);
Loop
assuming the loop is already working and that the t , delta, and w already exists as variables:
noconcatenate TABLE: load null() as t autogenerate(0);
do while t<b
let W=$(W)+$(t)*$(t);
let t=$(t)+$(delta);
concatenate(TABLE) load $(t) as t, $(W) as W autogenerate(1);
Loop
when you use the variable i think you need to encapsulate it with $(). but you need to test it
this look the same as a different post
Thank you for your prompt response.
What do you mean with that t, delta and w already exist as variable?
t is an increment variable within the loop. It should not be pre-defined.
delta is already pre-defined as : set delta=(b-a)/n.
w should be created within the loop. It should not be pre-defined.
Another problem here that I couldn't increment with a non decimal value. (e.g. delta=0.5)
if your increment is by .5 from 0 to 4 for example, you can loop from 0 to 8 and just divide your counter by 2 to simulate a .5 increment
Thank you. It worked with the increment. But it didn't with the main problem; storing of variables within the while loop.
Can you help me further.
Thank you in advance.
when you say it didnt work, what didnt work? was there an error message? can you give a hint?
try this:
set b=2;
set a=0;
set n=100;
set delta=(b-a)/n;
let W=0;
let t=0;
data:
load null() as t AutoGenerate(0);
do while t<b
let W=W+t*t;
let t=t+$(delta);
concatenate (data) load $(t) as t, $(W) as W AutoGenerate(1);
Loop
Hi edwin,
thank you for your reply. Unfortunately this error messages appears:
'Field names must be unique within table'
Only two fields should be generated (t and W)
I want to generate rows in respective fields.
Any help please?
Thanks in advance.
@AmCh i ran the script and there weren't any errors. this means you modified it and i get that. if you still need help maybe you can share your script?