I have an equation. I want to adjust one of the values in the equation until it hits a certain output. How do I run a loop to increment that certain value until it does this?

1 visualización (últimos 30 días)
equation: X/Y=P
Increase Y by an increment of 1 until gives an output equal or less than P.
Example:
X=21
Y=4
P=3
equation: 21/4=5.25
GOAL: increment Y unitl it gives an output less than or equal to P.

Respuestas (2)

Voss
Voss el 31 de En. de 2025
Editada: Voss el 31 de En. de 2025
X=21;
Y=4;
P=3;
while X/Y > P
Y = Y+1;
end
% this
Y
Y = 7
% is the first value of Y such that X/Y <= P
X/Y <= P
ans = logical
1
% (the previous value doesn't work since 21/6 > 3)
X/(Y-1) <= P
ans = logical
0

Matt J
Matt J el 31 de En. de 2025
Editada: Matt J el 31 de En. de 2025
X=21;
Y=4;
P=3;
increment=1;
Yp=X/P;
delta=ceil((Yp-Y)/increment);
Y=Y+delta
Y = 7

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by