我试图在matlab中求解一个线性方程组;方程的系数由用户在运行时提供。问题是解决方案是由matlab作为符号变量给出的,我无法将它们转换为人类可读的格式,如double。我的脚本:
% Accept coefficient of x in eqn one
a11 =input('Enter coefficient of x eqn one:');
%Accept coeff of y in eqn one
a12 = input('Enter coefficient of y in eqn one: ');
%Accept the constant term of eqn one
c1 = input('Enter the constant term in eqn one:');
%Form eqn one
eqn1 =sym( 'a11*x + a12*y + c1');
eqn_one = subs(eqn1, {a11, a12, c1},{a11, a12, c1})
a21 = input('Enter coefficient of x in eqn two:');
a22 = input('Enter coefficient of y in eqn two:');
c2 = input('Enter the constant term in eqn two:');
eqn2 = sym( 'a21*x + a22*y + c2');
eqn_two = subs(eqn2, {a21, a22, c2},{a21, a22, c2})
solve(eqn_one, eqn_two)
这是matlab的结果:
ans =
x: [1x1 sym]
y: [1x1 sym]
答案 0 :(得分:0)
您必须保存结果:
[x,y] = solve(eqn_one, eqn_two);
然后(如果你用';'终止了这一行)
display(x);display(y);
或者,如果您想要数字表达式,请使用文档查找:
disp(eval(x));disp(eval(y));
然而,正如所指出的,解决方案或根或类似函数可以在没有符号数学的情况下做同样的事情。这样做更好,因为maltab在符号方面真的很不方便。