MATLAB Answers

t1 range is 0.1 to 2 and t2 range is 0.1 to 2.....and t1+t2 should not be greater than 2

1 view (last 30 days)
RAVI
RAVI on 10 Apr 2018
Edited: Torsten on 13 Apr 2018
t1 range is 0.1 to 2 and t2 range is 0.1 to 2.....and t1+t2 should not be greater than 2

  4 Comments

Show 1 older comment
John D'Errico
John D'Errico on 10 Apr 2018
YESSIR. We will jump directly to writing your code. But you might have been specific about things. So if someone just tried to explain how to solve the problem, that would not help you?
t1 = 0.5;
t2 = 0.5;
There. Code. It satisfies the requirements.
Oh. Are t1 and t2 random variables? So you wanted to generate random numbers? If they are, what is the assumed distribution?
RAVI
RAVI on 10 Apr 2018
yes sir t1 and t2 are randomly generated number in the range of 0.1 to 2 and the total sum of t1 and t2 should be below 2 or 2.

Sign in to comment.

Accepted Answer

Birdman
Birdman on 10 Apr 2018
t1=0:0.1:2;
t2=0:0.1:2;
t=t1+t2;
t(t>2)=[];

  7 Comments

Show 4 older comments
Birdman
Birdman on 10 Apr 2018
RAVI's answer moved here:
t1=[0.1,0.1];
t2=[2,2];
var=2;
x=zeros(pop,var);
for i= 1:var
x(:,i)=t1(i)+(t2(i)-t1(i))*rand(pop,1);
end
suppose t1=1.2 than t2=0.8, the sum should not greater than 2
RAVI
RAVI on 13 Apr 2018
number which is greater than 2 it become zero but it also reflect the random number which sum is greater than two....plz reply
Torsten
Torsten on 13 Apr 2018
n=10;low=0.1;up=2;
t1=low+(up-low)*rand(1,n)
t2=low+(up-low)*rand(1,n)
t=t1+t2;
t1(t>2)=[];
t2(t>2)=[];
(t1(i),t2(i)) are the pairs you are looking for.
Best wishes
Torsten.

Sign in to comment.

More Answers (1)

Torsten
Torsten on 10 Apr 2018
Generate a pair of random numbers in the range [0.1:2].
Accept the pair if their sum is less or equal 2.
Repeat until you have generated enough feasible pairs.
Best wishes
Torsten.

  0 Comments

Sign in to comment.


Translated by