Errors while trying to setup equation for root finding.

1 回表示 (過去 30 日間)
Tom Goodland
Tom Goodland 2022 年 1 月 12 日
コメント済み: Walter Roberson 2022 年 1 月 16 日
I am trying to set up an equation for root finding to find a, however in the code at the bottom i get an error saying Parse error: Parse error at '=' . usage might be invalid syntax. Does anyone know how to fix this? I'd be grateful for any help.
x_pdo = z_pdo/(1 + a(k_pdo - 1));
x_water = z_water/(1 + a(k_water - 1));
x_glycerol = z_glycerol/(1 + a(k_glycerol - 1));
x_pdo + x_water + x_glycerol - 1 = 0;
  6 件のコメント
Torsten
Torsten 2022 年 1 月 12 日
If you have to insert the first three equations into the last to solve for a, also the x_... are unknown.
Otherwise, you could just pick one of the three equations at the top and solve for a.
Tom Goodland
Tom Goodland 2022 年 1 月 12 日
my mistake yeah the x_... are unknown, do you know what function I should use to try to determine a (constant) and x_...? I'm pretty sure fzero would work but I get the error a is an unrecognised function or variable. Do you know any code that would be able to calculate a from the code i've posted as information, if you need anymore information let me know.
Thanks for the help

サインインしてコメントする。

回答 (3 件)

James Tursa
James Tursa 2022 年 1 月 12 日
Did you mean multiply by the "a"?
x_pdo = z_pdo/(1 + a*(k_pdo - 1));
x_water = z_water/(1 + a*(k_water - 1));
x_glycerol = z_glycerol/(1 + a*(k_glycerol - 1));
  1 件のコメント
Tom Goodland
Tom Goodland 2022 年 1 月 12 日
yes do you have to put the * to multiply a by the bracket?

サインインしてコメントする。


Torsten
Torsten 2022 年 1 月 12 日
編集済み: Torsten 2022 年 1 月 12 日
function main
a0 = 1;
a = fzero(@fun,a0)
end
function res = fun(a)
z_pdo = ...;
k_pdo = ...;
z_water = ...;
k_water = ...;
z_glycerol = ...;
k_glycerol = ...;
res = z_pdo/(1 + a*(k_pdo - 1)) + z_water/(1 + a*(k_water - 1)) + z_glycerol/(1 + a*(k_glycerol - 1)) -1.0;
end
  22 件のコメント
Tom Goodland
Tom Goodland 2022 年 1 月 15 日
α is the vapour to feed ratio (α = FV / FCwhere FC is the feed flow rate and FV is the vapour flow rate)
Walter Roberson
Walter Roberson 2022 年 1 月 16 日
if a is the same as α then α(kj-1) is 0 when α is 0, and 1+0 is 1, so xj = zj/stuff would be xj=zj/1...

サインインしてコメントする。


Walter Roberson
Walter Roberson 2022 年 1 月 12 日
syms a k_pdo x_pdo x_glycerol z_pdo z_glycerol k_glycerol k_water x_water z_water
eqn1 = x_pdo == z_pdo/(1 + a*(k_pdo - 1));
eqn2 = x_water == z_water/(1 + a*(k_water - 1));
eqn3 = x_glycerol == z_glycerol/(1 + a*(k_glycerol - 1));
eqn4 = x_pdo + x_water + x_glycerol - 1 == 0;
eqns = [eqn1; eqn2; eqn3; eqn4]
eqns = 
sol = solve(eqns, [a, x_pdo, x_glycerol x_water])
sol = struct with fields:
a: [3×1 sym] x_pdo: [3×1 sym] x_glycerol: [3×1 sym] x_water: [3×1 sym]
sols = [sol.a, sol.x_pdo, sol.x_glycerol, sol.x_water]
sols = 
sol3 = solve(eqns, [a, x_pdo, x_glycerol x_water], 'maxdegree', 3);
sol3s = [sol3.a, sol3.x_pdo, sol3.x_glycerol, sol3.x_water];
vpa(sol3s)
ans = 

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by