Output 0x1 sym solving a system of equations
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (3)
Walter Roberson
am 11 Jan. 2024
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.
0 Kommentare
Torsten
am 11 Jan. 2024
Bearbeitet: Torsten
am 11 Jan. 2024
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)
[A,b] = equationsToMatrix(GLS)
rank(A)
x = A\b
0 Kommentare
Hassaan
am 11 Jan. 2024
Bearbeitet: Hassaan
am 11 Jan. 2024
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 Kommentar
Dyuman Joshi
am 11 Jan. 2024
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])
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!