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

조회 수: 2 (최근 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