using "solve" and getting rid of unknown parameters
6 ビュー (過去 30 日間)
古いコメントを表示
I am trying to solve a system of equations whose answer will depend on arbitrary values.
For example, consider the following system of 2 equations and 3 unknowns:
syms x1 x2 x3
E=[x1+2*x2+x3;x3-x1+x2];
a=solve(E==0,x1,x2,x3)
[a.x1 a.x2 a.x3]
this gives me an answer that depends on an arbitrary value z.
I would like MATLAB to directly give me an answer (with no arbitrary values). So for instance, I would like to get an answer where the x1 value is positive. Is there a way to do that?
I am using "solve" in a subroutine, and after that, I would like to test the answer to see if it is a non negative array. But whenever the code reaches the answer, it tells me there is an error (obviously) because of the unknown parameter.
0 件のコメント
回答 (2 件)
Azzi Abdelmalek
2013 年 1 月 14 日
編集済み: Azzi Abdelmalek
2013 年 1 月 14 日
You have 2 equations and 3 unknowns variables, which means there are infinite solutions. It's like your are solving
E=[x1+2*x2+z;z-x1+x2];
b=solve(E==0,x1,x2)
6 件のコメント
Azzi Abdelmalek
2013 年 1 月 14 日
編集済み: Azzi Abdelmalek
2013 年 1 月 14 日
There are your conditions, if for example you said that the first solution must be positive. The below code will choose one solution.
syms x1 x2 x3
E=[x1+2*x2+x3;x3-x1+x2];
a=solve(E==0,x1,x2,x3)
n= size(fieldnames(a),1)
z=solve(a.x1==1)
for k=1:n
sol(k)=eval(a.(sprintf('x%d',k)));
end
Walter Roberson
2013 年 1 月 14 日
That routine is not exposed at the MATLAB level so you would have to feval() or evalin() the symengine.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!