Errors while trying to setup equation for root finding.

1 view (last 30 days)
Tom Goodland
Tom Goodland on 12 Jan 2022
Commented: Walter Roberson on 16 Jan 2022
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 Comments
Tom Goodland
Tom Goodland on 12 Jan 2022
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

Sign in to comment.

Answers (3)

James Tursa
James Tursa on 12 Jan 2022
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
Torsten on 12 Jan 2022
Edited: Torsten on 12 Jan 2022
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 Comments
Walter Roberson
Walter Roberson on 16 Jan 2022
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...

Sign in to comment.


Walter Roberson
Walter Roberson on 12 Jan 2022
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 = 

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!