How to solve a multi variable inequality, where variables are a given set of numbers?

12 vues (au cours des 30 derniers jours)
syms B D L;
A=2860;
k=5900:20:7200;
B=k(randperm(numel(k),1));
C=34620;
l=27400:20:28240;
D=l(randperm(numel(l),1));
E=C-D;
F=E-A;
Q=5.9;
G=F/Q;
H=B/G;
m=4.5:0.1:5.3;
L=m(randperm(numel(m),1));
M=(H/(L+100))*100;
S=2.160;
N=(M/S)*100;
P=98.00<=N<=99.99;
W=solve(P,[B D L])
Value of B should be within 5900:20:7200. Value of D should be within 27400:20:28240. Value of L should be within 4.5:0.1:5.3. Value of N should be within 98.00:0.01:99.99.
I want to get multiple combinations of solutions in tabular form for [B D E F G H L M N].

Réponse acceptée

Dayalram Dayalram
Dayalram Dayalram le 16 Juin 2019
After doing little research I found out that it is not a problem of algebra, actually it is a problem of simple for loop problem. Here is how I solved it:
function compaction_values=fdd(lower,higher)
%FDD Field dry density.
% FDD(lower,higher) prints all combinations of values of A,B,C,D,E,
% F,G,H,L,M and Field Compaction accordingly, where field compaction's
% highest value is equal to input argument 'higher' and field compaction's
% lowest value is equal to input argument 'lower'.
%
% Note: The values of inputs 'lower' and 'higher' should be nonnegative
% real numbers. Negative values will print an error message.
if nargin ~= 2
error('Number of inputs must be two.');
elseif ~isscalar(lower) || ~isscalar(higher) || lower<0 || higher<0 || isempty(lower) || isempty(higher)
error('Inputs must be nonnegative scalars.');
else
A = 2860;
C = 34620;
S = 2.160;
Q = 1.349;
count = 0;
compaction_values=[];
for B = 6000:20:7100
for D = 27440:20:28180
for L = 5:-0.1:4.5
E = C-D;
F = E-A;
G = F/Q;
H = B/G;
M = (H/(L+100))*100;
compaction = (M/S)*100;
if compaction >=lower && compaction <= higher %This statement forces the function to print only needed values.
fprintf('%.0f %.0f %.0f %.0f %.0f %.0f %.0f %.2f %.1f %.2f %.2f\n',A,B,C,D,E,F,G,H,L,M,compaction);
compaction_values=[compaction_values;A,B,C,D,E,F,G,H,L,M,compaction];
count = count+1; %Counts the number of combinations.
end
end
end
end
fprintf('\ncount=%d\n',count);
end
end
You might have noticed some chages in data from the actual question but it's the same type of question.

Plus de réponses (0)

Catégories

En savoir plus sur Formula Manipulation and Simplification dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by