フィルターのクリア

range in symbolic form

7 ビュー (過去 30 日間)
riccardo agnesi
riccardo agnesi 2019 年 7 月 11 日
コメント済み: Walter Roberson 2019 年 8 月 8 日
I have this problem:
solution=feval(symengine, 'solve', '(abs(8/(k1+1)))<1', 'k1', 'Real')
solution = (7, Inf) union (-Inf, -9)
The solution is symbolic, but I need to have the two range in numeric form (array?) inside a script. Do I have to write about ten lines of code to do it? Thank you

採用された回答

riccardo agnesi
riccardo agnesi 2019 年 8 月 2 日
for my system I solved it this way alone.
I wanted something like that:
syms x
P = expand((x-3/2)*(x-5/4)*(x-1/10)*(x+4/8)*(x-12/5))
[ cond, condCell ] = inequality( P, 'x', 'P>0' )
The result, in symbolic form is: (-1/2, 1/10) union (5/4, 3/2) union (12/5, Inf). With my function, I have the result in numeric form (cond) and symbolic form, but separated into minimum and maximum.
cond =
-0.5000 0.1000
1.2500 1.5000
2.4000 Inf
condCell =
'-1/2' ' 1/10'
'5/4' ' 3/2'
'12/5' ' Inf'
I'm curious if there is another solution for my conditions (operating system xp, computer 20 years old, matlab 2010a)
function [ ra, racell ] = inequality( P, var, test )
test = subs(test,P);
s = feval(symengine, 'solve', test, var, 'Real')
if(isempty(s)) %no solution
ra=[1 -1]; %lower > higher
racell = {'no solution' ''};
else
s = char(s);
r = strfind(s,'R_');
if(isempty(r))
u = strfind(s,'union');
j = strfind(s,'Interval');
[r,c]=size(j);
%L=[0 0 0];
%racell = cell(1,2);
for(i=1:c)
if(i<c)
II = s(j(i)+9 : u(i)-3);
else
II = s(j(i)+9 : end -1);
end
kv = strfind(II,',');
v1 = II(1:kv-1);
v2 = II(kv+1:end);
try
L(i,:) = [sym2poly(vpa(v1)) sym2poly(vpa(v2)) i];
catch exception
L(i,:) = [(vpa(v1)) (vpa(v2)) i];
end
SS(i,1) = cellstr(v1);
SS(i,2) = cellstr(v2);
end
L = sortrows(L,1);
for(i=1:c)
ind = (L(i,3));
racell(i,1)=SS(ind,1);
racell(i,2)=SS(ind,2);
end
ra=L(:,1:2);
[ra racell] = checkrange(ra, racell);
else
ra = [-Inf Inf];
racell = {'-Inf' 'Inf'};
end
end
end
function [ra racell] = checkrange(rain, racellin)
[r,c] = size(rain);
j=1;
ra(j,1) = rain(1,1);
ra(j,2) = rain(1,2);
racell(j,1)=racellin(1,1);
racell(j,2)=racellin(1,2);
for i=2:r
if(rain(i,1) == rain(i-1,2))
ra(j,2) = rain(i,2);
racell(j,2)=racellin(i,2);
else
j = j + 1;
ra(j,1) = rain(i,1);
ra(j,2) = rain(i,2);
racell(j,1)=racellin(i,1);
racell(j,2)=racellin(i,2);
end
end
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 7 月 11 日
ch = children(solution);
[children(ch(1)),children(ch(2))]
  4 件のコメント
riccardo agnesi
riccardo agnesi 2019 年 7 月 12 日
Ops. I'm using a 20-year-old pc with the xp operating system and matlab 2010a
Walter Roberson
Walter Roberson 2019 年 8 月 8 日
I don't think I have a virtual machine for a MATLAB that old...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeUtilities for the Solver についてさらに検索

製品


リリース

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by