Error when solve system of equation using vpasolver

조회 수: 1 (최근 30일)
jin wang
jin wang 2015년 10월 13일
댓글: Torsten 2015년 10월 14일
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
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
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
jin wang
jin wang 2015년 10월 14일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
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.

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by