Page 1 of 1
How to compare the two parameters
Posted: Mon Jul 15, 2019 4:04 pm
by Lucas
Hi all,
How to compare the two parameters (0-1 parameters) together and find out if they are the same or not?
I wanted to use the Sameas command but I could not do it.
example compare 'a'
Code: Select all
set i/1*5/
k(i);
parameters
a(i) /1 1,2 0,3 1,4 0,5 0/
b(i) /1 0,2 1,3 1,4 0,5 0/
c(i) /1 1,2 0,3 1,4 0,5 0/
d(i) /1 1,2 0,3 1,4 0,5 1/
e(i) /1 1,2 1,3 1,4 0,5 1/
must to see a<>b and a=c, a<>d.
My try
Code: Select all
k(i)$(a(i))=yes;
scalar counter/0/
same/0/;
*count the number of index tha a(i) and b(i) are same
loop(i$,
counter=0;
if( abs(a(i)-b(i))< EPS,
counter= counter+1;
else
break;
);
);
if(counter=card(k),
same=1;
else
same=0;
display same;
);
I don't know How to use this methods for other parmeters (c,d,e,...) too? (in the loop?)
Thanks!
Re: How to compare the two parameters
Posted: Tue Jul 16, 2019 10:29 am
by Renger
Hi Lucas
Perhaps I don't get the question correctly, but here is a simpler way for comparing two parameters
Code: Select all
parameter same;
same = sum(i, abs(a(i)-b(i)));
if(same > 0,
display 'Parameter a is not equal to parameter b', same;);
Cheers
Renger
Re: How to compare the two parameters
Posted: Tue Jul 16, 2019 11:36 am
by Lucas
Hi Renger
first of all Thanks for your answer! your code is better than me!
I want to compare a parameter 'a' more than on time. How to compare 'a' with 'b' then 'a' with 'c' , 'a' with 'd' , 'a' with 'e' , without repeat the following code and change the b(i) to c(i), d(i) and e(i).
Code: Select all
parameter same;
same = sum(i, abs(a(i)-b(i)));
if(same > 0,
display 'Parameter a is not equal to parameter b', same;);
Thanks
Re: How to compare the two parameters
Posted: Tue Jul 16, 2019 5:20 pm
by dirkse
Lucas,
If you want to do this for many parameters, you could add an index and put all the parameters into a larger parameter. For example:
Code: Select all
set i/1*5/;
parameters
a(i) /1 1,2 0,3 1,4 0,5 0/
b(i) /1 0,2 1,3 1,4 0,5 0/
c(i) /1 1,2 0,3 1,4 0,5 0/
d(i) /1 1,2 0,3 1,4 0,5 1/
e(i) /1 1,2 1,3 1,4 0,5 1/
;
set p / a, b, c, d, e /;
alias(p,p1,p2);
parameter
data(p,i)
diff(p1,p2) 'count positions where p1 different from p2';
data('a',i) = a(i);
data('b',i) = b(i);
data('c',i) = c(i);
data('d',i) = d(i);
data('e',i) = e(i);
* you can do the whole diff, or just the upper triangle
diff(p1,p2) = sum{i, data(p1,i) <> data(p2,i)};
* diff(p1,p2)$[ord(p1) < ord(p2)] = sum{i, data(p1,i) <> data(p2,i)};
-Steve
Re: How to compare the two parameters
Posted: Tue Jul 16, 2019 5:20 pm
by Renger
Hi Lucas
This only might be possible like this:
Code: Select all
set i/1*5/
k(i);
parameters
a(i) /1 1,2 0,3 1,4 0,5 0/
b(i) /1 0,2 1,3 1,4 0,5 0/
c(i) /1 1,2 0,3 1,4 0,5 0/
d(i) /1 1,2 0,3 1,4 0,5 1/
e(i) /1 1,2 1,3 1,4 0,5 1/
;
set parset /a, b, c, d, e/;
parameter allparam(parset,i) All parameters;
allparam("a",i) = a(i);
allparam("b",i) = b(i);
allparam("b",i) = d(i);
allparam("b",i) = d(i);
allparam("b",i) = e(i);
parameter notequal(parset) Parameters not equal to a;
loop(parset,
if(sum(i, abs(allparam("a", i) - allparam(parset,i))) > 0,
notequal(parset) = 1;
);
);
display notequal;
Re: How to compare the two parameters
Posted: Tue Jul 16, 2019 6:09 pm
by Lucas
Dear Steve & Renger thanks a lot for your quick and useful answer!
Re: How to compare the two parameters
Posted: Thu Jul 18, 2019 7:06 am
by Lucas
Hi again
why I had this error?
Code: Select all
**** Macro Definition error for Macro ISsame: Closing parenthesis missing
when I used the Macro facility had that error! so I checked all parenthesis,it was ok, but I had same error again! what's wrong?
Code: Select all
set i/1*5/;
parameter
a(i) /1 1,2 0,3 1,4 0,5 0/
b(i) /1 0,2 1,3 1,4 0,5 0/
c(i) /1 1,2 0,3 1,4 0,5 0/
d(i) /1 1,2 0,3 1,4 0,5 1/
e(i) /1 1,2 1,3 1,4 0,5 1/;
parameter same;
*same = sum(i, abs(a(i)-b(i)));
*if(same > 0,
* display 'Parameter a is not equal to parameter b', same;);
* Define Macro
$macro ISsame(a(j),b(j)) same = sum(i, abs(a(i)-b(i))); if(same > 0,display 'Parameter a is not equal to parameter b', same;);
* End of Macro definition
* Call Macro
ISsame(a(j),b(j) )
Thanks in advance!
Re: How to compare the two parameters
Posted: Wed Jul 24, 2019 8:22 am
by Renger
Hi
Try this:
Code: Select all
$macro ISsame(a,b) same = sum(j, abs(a-b)); if(same > 0,display 'Parameter a is not equal to parameter b', same);
CHeers
Renger