Errors while trying to setup equation for root finding.
1 回表示 (過去 30 日間)
古いコメントを表示
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
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.
回答 (3 件)
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));
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 件のコメント
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
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]
sol = solve(eqns, [a, x_pdo, x_glycerol x_water])
sols = [sol.a, sol.x_pdo, sol.x_glycerol, sol.x_water]
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)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!