Output 0x1 sym solving a system of equations

6 次查看(过去 30 天)
Hi, I'm trying out symbolic math toolbox but am running into an 0-by 1 sym Output using this code:
clear
clc
close all
F1_NFR=1;
F2_NFR=1;
MIX_NFR=F1_NFR+F2_NFR;
syms F1_Solute_Molefraction F1_Solvent_Molefraction F1_Antisolvent_Molefraction;
syms F2_Solute_Molefraction F2_Solvent_Molefraction F2_Antisolvent_Molefraction;
syms MIX_Solute_Molefraction MIX_Solvent_Molefraction MIX_Antisolvent_Molefraction;
MIX_Solvent_Molefraction=0.3;
MIX_Solute_Molefraction=0.005;
F1_Antisolvent_Molefraction=0;
F1_Solute_Molefraction=0.01;
F2_Solute_Molefraction=0;
EQ1=F1_Antisolvent_Molefraction==1-F1_Solute_Molefraction-F1_Solvent_Molefraction;
EQ2=F2_Antisolvent_Molefraction==1-F2_Solute_Molefraction-F2_Solvent_Molefraction;
EQ3=MIX_Antisolvent_Molefraction==1-MIX_Solute_Molefraction-MIX_Solvent_Molefraction;
EQ4=MIX_Solute_Molefraction==(F1_NFR*F1_Solute_Molefraction+F2_NFR*F2_Solute_Molefraction)/MIX_NFR;
EQ5=MIX_Solvent_Molefraction==(F1_NFR*F1_Solvent_Molefraction+F2_NFR*F2_Solvent_Molefraction)/MIX_NFR;
EQ6=MIX_Antisolvent_Molefraction==(F1_NFR*F1_Antisolvent_Molefraction+F2_NFR*F2_Antisolvent_Molefraction)/MIX_NFR;
GLS=[EQ1,EQ2,EQ3,EQ4,EQ5,EQ6];
[sF2_Solvent_Molefraction sF2_Antisolvent_Molefraction]=solve(GLS, [F2_Solvent_Molefraction F2_Antisolvent_Molefraction]);
this system of equations should be solvable, but the output variables stay empty when I use solve for GLS. What am I doing wrong?

回答(3 个)

Walter Roberson
Walter Roberson 2024-1-11
you need to solve for the same number of variables as you have equations.
You do not have to pay attention to the uninteresting variables on output, but you have to solve for them anyhow. The results will be independent of all of the variables solved for.

Torsten
Torsten 2024-1-11
编辑:Torsten 2024-1-11
It seems your system of equations is inconsistent (it results in 0 = -1 for the fourth equation) :
clear
clc
close all
F1_NFR=1;
F2_NFR=1;
MIX_NFR=F1_NFR+F2_NFR;
syms F1_Solute_Molefraction F1_Solvent_Molefraction F1_Antisolvent_Molefraction;
syms F2_Solute_Molefraction F2_Solvent_Molefraction F2_Antisolvent_Molefraction;
syms MIX_Solute_Molefraction MIX_Solvent_Molefraction MIX_Antisolvent_Molefraction;
MIX_Solvent_Molefraction=0.3;
MIX_Solute_Molefraction=0.005;
F1_Antisolvent_Molefraction=0;
F1_Solute_Molefraction=0.01;
F2_Solute_Molefraction=0;
EQ1=F1_Antisolvent_Molefraction==1-F1_Solute_Molefraction-F1_Solvent_Molefraction;
EQ2=F2_Antisolvent_Molefraction==1-F2_Solute_Molefraction-F2_Solvent_Molefraction;
EQ3=MIX_Antisolvent_Molefraction==1-MIX_Solute_Molefraction-MIX_Solvent_Molefraction;
EQ4=MIX_Solute_Molefraction==(F1_NFR*F1_Solute_Molefraction+F2_NFR*F2_Solute_Molefraction)/MIX_NFR;
EQ5=MIX_Solvent_Molefraction==(F1_NFR*F1_Solvent_Molefraction+F2_NFR*F2_Solvent_Molefraction)/MIX_NFR;
EQ6=MIX_Antisolvent_Molefraction==(F1_NFR*F1_Antisolvent_Molefraction+F2_NFR*F2_Antisolvent_Molefraction)/MIX_NFR;
GLS=[EQ1,EQ2,EQ3,EQ4,EQ5,EQ6];
symvar(GLS)
ans = 
[A,b] = equationsToMatrix(GLS)
A = 
b = 
rank(A)
ans = 4
x = A\b
Warning: Solution does not exist because the system is inconsistent.
x = 

Hassaan
Hassaan 2024-1-11
编辑:Hassaan 2024-1-11
clear
clc
close all
syms F1_Solute_Molefraction F1_Solvent_Molefraction F1_Antisolvent_Molefraction;
syms F2_Solute_Molefraction F2_Solvent_Molefraction F2_Antisolvent_Molefraction;
syms MIX_Solute_Molefraction MIX_Solvent_Molefraction MIX_Antisolvent_Molefraction;
F1_NFR = 1;
F2_NFR = 1;
MIX_NFR = F1_NFR + F2_NFR;
% Define the equations
EQ1 = F1_Antisolvent_Molefraction == 1 - F1_Solute_Molefraction - F1_Solvent_Molefraction;
EQ2 = F2_Antisolvent_Molefraction == 1 - F2_Solute_Molefraction - F2_Solvent_Molefraction;
EQ3 = MIX_Antisolvent_Molefraction == 1 - MIX_Solute_Molefraction - MIX_Solvent_Molefraction;
EQ4 = MIX_Solute_Molefraction == (F1_NFR * F1_Solute_Molefraction + F2_NFR * F2_Solute_Molefraction) / MIX_NFR;
EQ5 = MIX_Solvent_Molefraction == (F1_NFR * F1_Solvent_Molefraction + F2_NFR * F2_Solvent_Molefraction) / MIX_NFR;
EQ6 = MIX_Antisolvent_Molefraction == (F1_NFR * F1_Antisolvent_Molefraction + F2_NFR * F2_Antisolvent_Molefraction) / MIX_NFR;
% Solve the equations
[sF2_Solvent_Molefraction, sF2_Antisolvent_Molefraction] = solve([EQ1, EQ2, EQ3, EQ4, EQ5, EQ6], [F2_Solvent_Molefraction, F2_Antisolvent_Molefraction]);
% Substitute the numeric values
MIX_Solvent_Molefraction_val = 0.3;
MIX_Solute_Molefraction_val = 0.005;
F1_Antisolvent_Molefraction_val = 0;
F1_Solute_Molefraction_val = 0.01;
sF2_Solvent_Molefraction = subs(sF2_Solvent_Molefraction, {MIX_Solvent_Molefraction, MIX_Solute_Molefraction, F1_Antisolvent_Molefraction, F1_Solute_Molefraction}, {MIX_Solvent_Molefraction_val, MIX_Solute_Molefraction_val, F1_Antisolvent_Molefraction_val, F1_Solute_Molefraction_val});
sF2_Antisolvent_Molefraction = subs(sF2_Antisolvent_Molefraction, {MIX_Solvent_Molefraction, MIX_Solute_Molefraction, F1_Antisolvent_Molefraction, F1_Solute_Molefraction}, {MIX_Solvent_Molefraction_val, MIX_Solute_Molefraction_val, F1_Antisolvent_Molefraction_val, F1_Solute_Molefraction_val});
disp(sF2_Solvent_Molefraction);
disp(sF2_Antisolvent_Molefraction);
This approach maintains the symbolic nature of the variables while solving the equations and only substitutes the numeric values after the symbolic solution is found. Remember to verify and adjust the equations and variables according to the specifics of your problem.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
  1 个评论
Dyuman Joshi
Dyuman Joshi 2024-1-11
Not only does it not answer OP's question, your answer returns the same output.
Walter has correctly pointed out what needs to be done.
syms F1_Solute_Molefraction F1_Solvent_Molefraction F1_Antisolvent_Molefraction;
syms F2_Solute_Molefraction F2_Solvent_Molefraction F2_Antisolvent_Molefraction;
syms MIX_Solute_Molefraction MIX_Solvent_Molefraction MIX_Antisolvent_Molefraction;
F1_NFR=1;
F2_NFR=1;
MIX_NFR=F1_NFR+F2_NFR;
EQ1 = F1_Antisolvent_Molefraction == 1 - F1_Solute_Molefraction - F1_Solvent_Molefraction;
EQ2 = F2_Antisolvent_Molefraction == 1 - F2_Solute_Molefraction - F2_Solvent_Molefraction;
EQ3 = MIX_Antisolvent_Molefraction == 1 - MIX_Solute_Molefraction - MIX_Solvent_Molefraction;
EQ4 = MIX_Solute_Molefraction == (F1_NFR*F1_Solute_Molefraction + F2_NFR*F2_Solute_Molefraction) / MIX_NFR;
EQ5 = MIX_Solvent_Molefraction == (F1_NFR*F1_Solvent_Molefraction + F2_NFR*F2_Solvent_Molefraction) / MIX_NFR;
EQ6 = MIX_Antisolvent_Molefraction == (F1_NFR*F1_Antisolvent_Molefraction + F2_NFR*F2_Antisolvent_Molefraction) / MIX_NFR;
GLS = [EQ1, EQ2, EQ3, EQ4, EQ5, EQ6];
[sF2_Solvent_Molefraction, sF2_Antisolvent_Molefraction] = solve(GLS, [F2_Solvent_Molefraction, F2_Antisolvent_Molefraction])
sF2_Solvent_Molefraction = Empty sym: 0-by-1 sF2_Antisolvent_Molefraction = Empty sym: 0-by-1

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by