How to solve symbolic system of equations?
15 次查看(过去 30 天)
显示 更早的评论
Hello,
I am dynamically generating a system of symbolic linear equations that I trying to figure out how to solve. For example,
syms a b c
Eqs = [3*a + 4*b + 7*c + 11; 5*a + 3*b + 3*c + 4; 7*a + 13*b + 5*c + 9];
Since these equations are dynamically generated based on user parameters, the variables names can change and so forth, so that is why I need to do this symbolically.
If you do:
rref(Eqs)
you get ans =[1; 0; 0] which is weird.
If anyone knows how to solve this, please let me know. I would appreciate it. If anyone can let me know how to parse these symbolic expressions, I would appreciate it too. How to separate and isolate different variables.
Thanks, Ali
0 个评论
采纳的回答
Kenneth Eaton
2011-1-26
>> S = solve(Eqs)
S =
a: [1x1 sym]
b: [1x1 sym]
c: [1x1 sym]
And you can convert the symbolic results in these fields to numeric values using the functions SUBS or DOUBLE:
>> subs(S.a)
ans =
0.2773
Or you could convert all the fields to numeric values and place them in a vector with one call to STRUCTFUN:
>> structfun(@subs,S)
ans =
0.2773 % The value for a
-0.2455 % The value for b
-1.5500 % The value for c
5 个评论
Walter Roberson
2011-1-27
You can use symvar() and coeff() to extract the variables and their coefficients from multinomial systems.
更多回答(1 个)
Paulo Silva
2011-1-27
%'3*a + 4*b + 7*c + 11=0' -> '3*a + 4*b + 7*c = -11'
%'5*a + 3*b + 3*c + 4=0' -> '5*a + 3*b + 3*c = -4'
%'7*a + 13*b + 5*c + 9=0' -> '7*a + 13*b + 5*c = -9'
A=[3 4 7
5 3 3
7 13 5];
B=[-11
-4
-9];
X=linsolve(A,B); or X=A\B , same results
a=X(1);
b=X(2);
c=X(3);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!