Error when solve system of equation using vpasolver

6 views (last 30 days)
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 Comment
Torsten
Torsten on 14 Oct 2015
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.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 13 Oct 2015
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 Comment
jin wang
jin wang on 14 Oct 2015
if I change the way you write it as the second option, the error says
Undefined function 'vpasolve' for input arguments of type 'double'.
Error in solveBF (line 18) [BF1,BF2,BF3,BF4,CO,COreq] = vpasolve([eqn1,eqn2,eqn3,eqn4,eqn5,eqn6], [BF1,BF2,BF3,BF4,CO,COreq]);
Error in test (line 159) [BF1,BF2,BF3,BF4,CO,COreq] = solveBF(k,MaxBFvsk,PctBF,MuVO2,COmax,BF1,BF2,BF3,BF4,CO,COreq);

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 14 Oct 2015
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.

Categories

Find more on Get Started with Symbolic Math Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!