简体   繁体   中英

Solving a symbolic, nonlinear equation in Matlab/Octave

I'm trying to solve the following steady-state equation for 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. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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