简体   繁体   English

在 Matlab/Octave 中求解符号非线性方程

[英]Solving a symbolic, nonlinear equation in Matlab/Octave

I'm trying to solve the following steady-state equation for x:我正在尝试求解 x 的以下稳态方程:

0 = -C + 2*C0*(1-exp(-k*A*x*phi))

I've defined all variables as syms , but can't figure out how to solve the equation for x.我已将所有变量定义为syms ,但无法弄清楚如何求解 x 的方程。 Since all other variables are known, I've tried substituting them in:由于所有其他变量都是已知的,我尝试将它们替换为:

f = -C + 2*C0*(1-exp(-k*A*x*phi))
subs(f, [C 20], [C0 11], [k .015], [A .031], [phi .01])

But this also doesn't work.但这也行不通。

The correct way to replace symbolic variables with values using subs is to use the three input variant.使用subs用值替换符号变量的正确方法是使用三个输入变量。 The first is the symbolic expression, the second is an array of symbolic variables to replace, and the third is an array of things that you want to replace each variable in the second input with.第一个是符号表达式, 第二个是要替换的符号变量数组, 第三个是要替换第二个输入中的每个变量的数组。

syms C C0 k A x phi

f = -C + 2*C0*(1-exp(-k*A*x*phi));

% Substitute in values that are known
newf = subs(f, [C, C0, k, A, phi], [20, 11, 0.015, 0.031, 0.01]);
%   2 - 22*exp(-(93*x)/20000000)

% Solve the resulting symbolic expression for x
result = solve(newf == 0, x)
%   (20000000*log(11))/93

% And if you need a numeric (rather than symbolic) result
double(result)
%   5.1568e+05

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM