rearrange system of equations
4 ビュー (過去 30 日間)
古いコメントを表示
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:
- solve eq2 for b and substitute into eq 1 gives eq11: a+e-d=c
- solve eq3 for d and substitute into eq11 gives eq12: a+e-(g-f)=c
- 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.
0 件のコメント
回答 (2 件)
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 件のコメント
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 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!