Extract positive value from solve function
3 ビュー (過去 30 日間)
古いコメントを表示
eqs = [(A-a1) == d, (A-a2) == d2;
S = solve(eqs, [A B]);
a = S.A
b = S.B
In the code above, all other variables are given so i AM solving for A and B. The code above alrEADY works and displays a solution but how will I extract the positive values of the solution only , and assign them to variables a and b?
0 件のコメント
回答 (1 件)
Torsten
2022 年 4 月 3 日
編集済み: Torsten
2022 年 4 月 3 日
If a and b contain no more symbolic constants, then you can use
a = double(a);
b = double(b);
a = a(abs(imag(a)) < 1e-6);
b = b(abs(imag(b)) < 1e-6);
a = real(a);
b = real(b);
A = [];
B = [];
iter = 0;
for i = 1:numel(a)
if a(i) >= 0 && b(i) >= 0
iter = iter + 1;
A(iter) = a(i);
B(iter) = b(i);
end
end
A
B
2 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!