Question

I have a function f(x) whose range is the interval [0, 1], and I need to...

I have a function f(x) whose range is the interval [0, 1], and I need to shift it and stretch it so that the range is now the interval [a, b]. Find a function g(x) (defined in terms of f(x)) so that g(x) has an range [a, b].

In Matlab, the rand command produces a random number between 0 and 1, under the uniform distribution; that's different from the normal distribution. The graph of the uniform probability distribution is a horizontal line. The graph of the normal distribution is the bell curve.

I need a program that will accept input values a and b, a < b, and will output a random number between a and b, You'll do this by shifting and stretching the rand function. Notice that in Matlab the rand function doesn't take an input. You just type rand and hit enter, and the program will spit out a random number between 0 and 1.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a=input('Input a: ');
b=input('Input b: ');
%rand() produces from 0 to 1
%we need it to produce values from a to b, or in the range of (b-a)
%if we multiply it with (b-a), then it will produce in the range 0 to (b-a)
%if we then add a to it, the range becomes (0+a) to (b-a)+a
% which becomes a to b, which is what required
%hence is we want rand() to produce a number from a to b, and we denote
%f(x) as rand,
%then g(x) = (b-a)*f(x) + a
randomNumber = a + rand()*(b-a);
disp(randomNumber)

Command Window >> randomNum_ba Input a: 2 Input b: 8 2.7619 >> randomNum_ba Input a: 2 Input b: 3 2.9134 fx >>

Add a comment
Know the answer?
Add Answer to:
I have a function f(x) whose range is the interval [0, 1], and I need to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT