Effacer les filtres
Effacer les filtres

How to access bounds of conditions obtained from solving matlab inequalities ?

1 vue (au cours des 30 derniers jours)
Hello,
I am trying to solve a matlab inquality for a function such as y = f(x).
using matlab vpasolver.
r = solve(y>0,x,"Real",true,'ReturnConditions', true)
Now, i obtain the solution of this inequality which looks like following.
r =
struct with fields:
x: [1×1 sym]
parameters: [1×1 sym]
conditions: [1×1 sym]
when i access the conditions by r.conditions, i obtain
0.77726530669995618438861129106954 <= x
which is correct. I now want to use this numerical limit of 0.7772... . I am not able to acess this value from conditions. can anyone tell me how to do it ?
i tried to convert it into string as well but it didnt work.
thanks !

Réponse acceptée

Hassaan
Hassaan le 23 Fév 2024
Modifié(e) : Hassaan le 23 Fév 2024
syms x
y = x^2 - 3*x + 2; % Example function
r = solve(y > 0, x, 'Real', true, 'ReturnConditions', true);
% Extract the condition
cond = r.conditions;
% Assume the condition is in the form of an inequality like '0.777 <= x'
% We can convert this condition to a string and then extract the numeric part
condStr = string(cond); % Convert to string
numStr = regexp(condStr, '[\d.]+', 'match'); % Extract numeric part as string
% Now, convert the string to a numeric value
numVal = str2double(numStr{1});
disp(numVal)
2
Note
  • Other approaches may also exist.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Plus de réponses (1)

Torsten
Torsten le 23 Fév 2024
Déplacé(e) : Torsten le 23 Fév 2024
syms x
r.conditions = 0.77726 <= x
r = struct with fields:
conditions: 38863/50000 <= x
lhs(r.conditions)
ans = 

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by