所以我想知道如何将预定义的变量输入到方程本身中。
这是代码。
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都应该是你输入的数字。
答案 0 :(得分: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)
是要走的路。