I have an R coding question which I want to share. Suppose we have the following:
z1= c(2, 4, 6, 8)
s1= seq(-13, 14, by = 0.1)
s2= seq(-13, 14, by = 0.1)
Function<-function(s1,s2){
Y<-matrix(0,nrow=length(s1),ncol=length(z1))
for (j in 1:length(s1)){
for (i in 1:length(z1)){
Y[j,i]<- s1[j]*s2[j] + z1[i]}}
return(Y)
}
So, s1 and s2 are the inputs, and they can have any values in the interval [-13, 14]. They can have the same value, or different values as well for each time.
Now, I wonder how to identify which combinations of s1 and s2 produce outpots that are (all) less than a certain threshold, say 20. For example, if s1= 2
and s2= 4
then we know the function above has four outputs (four because i=1,...,4), which are as follows:
Y= 8+ 2 for i=1
Y= 8+ 4 for i=2
Y= 8+ 6 for i=3
Y= 8+ 8 for i=4
In this case, all of these outpots are less than 20 so that the combination (2,4) is possible to be chosen. But, how to apply this to the whole range of the possible values of s1 and s2 and then choose only those combinations whose outputs are all less than 20? Any hint is really appriciated.
Thanks!