Error when solve system of equation using vpasolver
1 次查看(过去 30 天)
显示 更早的评论
function [BF1,BF2,BF3,BF4,CO,COreq] = solveBF(k,MaxBFvsk,PctBF,MuVO2,COmax,BF1,BF2,BF3,BF4,CO,COreq)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
syms BF1(k) BF2(k) BF3(k) BF4(k) CO(k) COreq(k)
eqn1 = BF3(k)-(0.012*CO(k)); %ml/min
eqn2 = BF1(k)-(0.92*CO(k)); %ml/min
eqn3 = BF4(k)-(MaxBFvsk*PctBF*1000); %ml/min
eqn4 = BF2(k)-((100*MuVO2)/(0.8*210));
eqn5 = COreq(k)-BF1(k)-BF2(k)-BF3(k)-BF4(k);
eqn6 = CO(k)-(0.5*(COreq(k)+COmax)); %ml/min CO=HRR*SV is another method
[BF1,BF2,BF3,BF4,CO,COreq] = vpasolve(eqn1,eqn2,eqn3,eqn4,eqn5,eqn6);
end
And the error says:
Error using sym/vpasolve (line 149)
Input with 1 variables and output with 6 variables are inconsistent.
Error in solveBF (line 20)
[BF1,BF2,BF3,BF4,CO,COreq] = vpasolve(eqn1,eqn2,eqn3,eqn4,eqn5,eqn6);
Error in test (line 159)
[BF1,BF2,BF3,BF4,CO,COreq] =
solveBF(k,MaxBFvsk,PctBF,MuVO2,COmax,BF1,BF2,BF3,BF4,CO,COreq);
1 个评论
Torsten
2015-10-14
Not clear why BF1,BF2,BF3,BF4,CO,COreq appear as input and output arguments in your function solveBF. In my opinion, they are only output values.
Best wishes
Torsten.
采纳的回答
Star Strider
2015-10-13
The easiest way to find out what variables vpasolve is solving for is to re-write it as:
solution = vpasolve(eqn1,eqn2,eqn3,eqn4,eqn5,eqn6);
That will return the variables it finds, in the ‘solution’ structure. You can then see what they are.
Another possibility is to rewrite it as:
[BF1,BF2,BF3,BF4,CO,COreq] = vpasolve([eqn1,eqn2,eqn3,eqn4,eqn5,eqn6], [BF1,BF2,BF3,BF4,CO,COreq]);
See which one works best.
更多回答(1 个)
Walter Roberson
2015-10-14
When you use
syms BF1(k) BF2(k) BF3(k) BF4(k) CO(k) COreq(k)
you are doing
BF1 = sym('unapply(BF1,k)');
BF2 = sym('unapply(BF2,k)');
or similar. In each case you are disconnecting what was passed in as BF1, BF2, etc., from the local meaning of BF1, BF2, etc., just the same way as the below disconnects "x" from what was passed in.
function solveBF(x)
x = 5;
"syms" is an assignment statement, not a type declaration.
syms X
means like
syms = @(Name) assignin('caller', Name, sym(Name)); %remember syms is called in command syntax so parameters are strings
If your input BF1, BF2, and so on are already symbolic functions, then you do not need to syms them: MATLAB will already know their datatype is symbolic, the same way it would know the datatype of "x" in my above example. If the inputs are not already symbolic functions then you need to use different names for your syms and possibly subs() the input BF1, BF2 and so on in to those functions or call the functions with those input values.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!