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我的代码,求出的结果带入f1~f12,发现都不为0,这是为什么? 展开
原因
使用solve函数求解方程组,如果返回多个参数,则参数是按照字母顺序排列,而与你在输入参数表中指定的顺序无关。
可参考关于solve函数的文档:
Three different types of output are possible. For one equation and one
output, the resulting solution is returned, with multiple solutions to
a nonlinear equation in a symbolic vector. For several equations and
an equal number of outputs, the results are sorted in lexicographic
order and assigned to the outputs. For several equations and a single
output, a structure containing the solutions is returned.
建议
一种方式是,修改solve函数的输出参数顺序:
[C1,C2,C3,C4,D2,D3,D4,F1,F2,F3,F4,F5]=solve(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,'F1','F2','F3','F4','F5','C1','C2','C3','C4','D2','D3','D4')
或者,按照下面的方式返回参数:
s=solve(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,'F1','F2','F3','F4','F5','C1','C2','C3','C4','D2','D3','D4');
fns = fieldnames(s);
for i=1:length(fns)
eval([fns{i} '=s.' fns{i}]);
end