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

2 ビュー (過去 30 日間)
Rahul Sharma
Rahul Sharma 2024 年 2 月 23 日
コメント済み: Rahul Sharma 2024 年 2 月 24 日
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 Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by