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

1 次查看(过去 30 天)
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 !

采纳的回答

Hassaan
Hassaan 2024-2-23
编辑:Hassaan 2024-2-23
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.

更多回答(1 个)

Torsten
Torsten 2024-2-23
移动:Torsten 2024-2-23
syms x
r.conditions = 0.77726 <= x
r = struct with fields:
conditions: 38863/50000 <= x
lhs(r.conditions)
ans = 

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by