rearrange system of equations

4 ビュー (過去 30 日間)
Daniel
Daniel 2012 年 11 月 15 日
The problem is fairly simple from the mathematical point. I just dont know how to do it, i.e. which command would be the right one to use.
Let a system of equations be given, such as
eq1: a+b=c
eq2: b+d=e
eq3: d+f=g
Basically, all I want to do is to express "a" as function of "f", i.e. a(f) = ...
By hand one would do as follows:
  1. solve eq2 for b and substitute into eq 1 gives eq11: a+e-d=c
  2. solve eq3 for d and substitute into eq11 gives eq12: a+e-(g-f)=c
  3. eq12 is the solution to the problem; "a" is a function depending on f(among the other variables) a(f)=c-e+(g-f) = c-e+g-f
Also, i want to automate the routine so that one can easily choose dependent and independent variable (i.e. a(f), c(g), etc.). The size of the system changes for different runs.
In summary, i wonder if there is a command which lets me rearrange the given system of equations to fit the desired format (express as function of certain variable), kind of like an iterative "isolate" for a system of equations.
Thanks.

回答 (2 件)

Babak
Babak 2012 年 11 月 15 日
You could use the Simbolic Math toolbox and its commands to do all these. syms, subs, vpa would be commands in Simbolic Math toolbox I would recommend you look into.
  3 件のコメント
Walter Roberson
Walter Roberson 2012 年 11 月 16 日
solve(eq1, eq2, eq3, a)
Daniel
Daniel 2012 年 11 月 16 日
Walter, this is what I initially thought, but it just doesn't work (tried with the various call options, too). It throws the following message:
Warning: 3 equations in 1 variables.
Warning: Explicit solution could not be found.
ans = [ empty sym ]
Any idea beyond that?

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


Star Strider
Star Strider 2012 年 11 月 16 日
編集済み: Star Strider 2012 年 11 月 16 日
I'm still not certain exactly what you want to do, but you could consider yours to be a sparse matrix problem. In that situation:
a = 3; b = 5; d = 11; f = 17;
M = [ 1 1 0 0; 0 1 1 0; 0 0 1 1];
P = [a; b; d; f];
V = M*P;
Ps = lsqr(M,V);
fprintf(1,'\n\ta = %f\n\tb = %f\n\td = %f\n\tf = %f\n', Ps)
This approach might also suggest a way for you to automate it to accomodate different matrix sizes for different runs.
  2 件のコメント
Daniel
Daniel 2012 年 11 月 16 日
Star Strider - thanks for your input. Unfortunately, i dont fully understand what you mean - can you elaborate a little.
What i try to do (see introductory example) is to automate the following: given a system of equations i want to express one unknown (dependent variable, a in the example) in terms of another unknown (independent variable, f in the example). Here, dependent and independent variable are not given in the same equation, so that by hand one would rearrange the additionally given equations (eq2, eq3) and substitute them into the principal equation (eq1)until eq1 is in a format that it contains the desired variables (here a(f)). I edited the original question to better explain the problem.
Star Strider
Star Strider 2012 年 11 月 16 日
編集済み: Star Strider 2012 年 11 月 16 日
I beleive the nature of the systems you want to solve is the reason the Symbolic Toolbox functions won't work for you. The approach I outlined uses the Sparse Matrices functions (specifically lsqr) to solve the system I coded above, that is equivalent to:
[a b 0 0] [c]
[0 b d 0] = [e]
[0 0 d f] [g]
in the form I used here:
M * P = V
then solve for P in terms of M and V.
Alternatively, to solve for f:
% d + f = g -> f = g - d
a = 3; b = 5; d = 11; g = 17;
M = [ 1 1 0 0; 0 1 1 0; 0 0 -1 1];
P = [a; b; d; g];
... etc.
You have to use sparse matrix routines on systems like these. The mldivide function will not work, and using the Symbolic Toolbox on this problem returned me only the trivial solution, a vector of zeros.
I can't be more specific because I don't know the sort of run-to-run rearrangements of your matrices and resultant vectors you want to do. You could in theory automate this by creating the appropriate matrices and result vectors, and the solving for the coefficient vectors as I did here, but how you do that would depend on what you want to do. Given the nature of the system you outlined, sparse matrix routines are likely to be the only way to solve it.
Note that you have an underdetemined system, so only lsqr will work. It will give you an answer. That answer is lsqr’s best attempt, but it may be neither unique nor necessarily correct.

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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by