0

所以我想知道如何将预定义的变量输入到方程本身中。

这是代码。

function[A, B, C] = A_B_C_problem_generalized(lambda_1, lambda_2, mu_1, mu_2, gamma_1, gamma_2)

clear
clc
syms a1 a2 a4 b1 b2 b4 c1 c2 c4

[a1, a2, a4, b1, b2, b4, c1, c2, c4] = ...
solve('a1 + a4 = lambda_1 + lambda_2', ...
'a1*a4 - a2^2 = lambda_1 * lambda_2', ...
'b1 + b4 = mu_1 + mu_2', ...
'b1*b4 - b2^2 = mu_1 * mu_2', ...
'c1 + c4 = gamma_1 + gamma_2', ...
'c1*c4 - c2^2 = gamma_1 * gamma_2', ...
'c1 = a1 + b1', ...
'c2 = a2 + b2', ...
'c4 = a4 + b4');
...

我怎么能这样做呢?lambda、mu 和 gamma 应该是您输入的数字。

4

1 回答 1

0

啊,正确的方法是不使用字符串。相反,将其转换为求根问题,如果您将所有内容移到等式的一侧,求解器会自行完成...

syms a1 a2 a4 b1 b2 b4 c1 c2 c4

[a1, a2, a4, b1, b2, b4, c1, c2, c4] = ...
solve(a1 + a4 - (lambda_1 + lambda_2), ...
a1*a4 - a2^2 - (lambda_1*lambda_2), ...
b1 + b4 - (mu_1 + mu_2), ...
b1*b4 - b2^2 - (mu_1*mu_2), ...
c1 + c4 - (gamma_1 + gamma_2), ...
c1*c4 - c2^2 - (gamma_1*gamma_2), ...
c1 - a1 - b1, ...
c2 - a2 - b2, ...
c4 - a4 - b4)

是要走的路。

于 2012-11-01T19:10:18.373 回答