I have an equation with 3 variables that each have an allowable range of values, how can I compute all possible solutions by picking from the allowable range of values at random?

1 view (last 30 days)
The equation is quite simple:
F = E * B + Q * (B/K)
B stays constant
E, Q, and K all have an allowable range in values
E can be 0.02 to 0.06
Q can be 250 to 500
K can be 1E+4 to 1E+6
I simply want to evaluate the equation and see all the possible values for F by 'picking' from the allowable ranges at random. Essentially, it is a simple Monte Carlo, however it is not so simple to figure out how to achieve this in MATLAB at present for me. Any advice would be greatly appreciated.

Accepted Answer

Mohammad Sami
Mohammad Sami on 2 Apr 2020
B = 1.71E11;
F = @(E,Q,K) E.*B + Q.* (B./K);
mnE = 0.02;
mxE = 0.06;
numval = 100;
E = rand(numval,1) .*(mxE-mnE) + mnE; % generate 100 values for E
mnQ = 250;
mxQ = 500;
Q = rand(numval,1) .*(mxQ-mnQ) + mnQ; % generate 100 values for Q
mnK = 1E4;
mxK = 1E6;
K = rand(numval,1) .*(mxK-mnK) + mnK; % generate 100 values for K
out = F(E,Q,K);

More Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!