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

2 views (last 30 days)
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 !

Accepted Answer

Hassaan
Hassaan on 23 Feb 2024
Edited: Hassaan on 23 Feb 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.

More Answers (1)

Torsten
Torsten on 23 Feb 2024
Moved: Torsten on 23 Feb 2024
syms x
r.conditions = 0.77726 <= x
r = struct with fields:
conditions: 38863/50000 <= x
lhs(r.conditions)
ans = 

Categories

Find more on Symbolic Math Toolbox 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!