undefined variable problem using vpasolve

조회 수: 4 (최근 30일)
Vincent Nent
Vincent Nent 2023년 7월 2일
댓글: Vincent Nent 2023년 7월 2일
So i need to solve a set of equations and wrote some code for that. Im not very confident in my matlab skills but i cant find the mistake in here. Im getting undefined variable error over and over again.
Heres the Code maybe someone here can help me.
% Parameter
A_1 = 8.23714;
A_2 = 8.19625;
B_1 = 1592.864;
B_2 = 1730.63;
C_1 = 226.184;
C_2 = 233.426;
c1 = 1.701;
c2 = 0.9425;
p = 1022.48; % [mbar]
T = 80; % [°C]
g1 = exp((c1.*((1-x1)).^2)./(((1-x1)+(c1/c2).*x1).^2));
g2 = exp((c2.*(x1).^2)./((x1+(c2/c1).*(1-x1)).^2));
p1 = 10^(A_1-(B_1./(T+C_1)));
p2 = 10^(A_2-(B_2./(T+C_2)));
syms x1
eqn = (g1.*p1.*x1)+(g2.*p2.*(1-x1))-p==0;
S = vpasolve(eqn,x1)
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 7월 2일
syms x1 before you define g1 since g1 and g2 use x1

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

채택된 답변

Shantanu Dixit
Shantanu Dixit 2023년 7월 2일
Hi Vincent,
The error you are encountering is due to the fact that you are using the symbolic variable x1 in the calculations before declaring it as a symbolic variable using the syms function.
To resolve it, you need to declare x1 as a symbolic variable before using it in the equations.
% Parameter
A_1 = 8.23714;
A_2 = 8.19625;
B_1 = 1592.864;
B_2 = 1730.63;
C_1 = 226.184;
C_2 = 233.426;
c1 = 1.701;
c2 = 0.9425;
p = 1022.48; % [mbar]
T = 80; % [°C]
% Declare x1 as a symbolic variable
syms x1
% Calculate g1 and g2
g1 = exp((c1.*((1-x1)).^2)./(((1-x1)+(c1/c2).*x1).^2));
g2 = exp((c2.*(x1).^2)./((x1+(c2/c1).*(1-x1)).^2));
% Calculate p1 and p2
p1 = 10^(A_1-(B_1./(T+C_1)));
p2 = 10^(A_2-(B_2./(T+C_2)));
% Define the equation
eqn = (g1.*p1.*x1) + (g2.*p2.*(1-x1)) - p == 0;
% Solve the equation symbolically
S = vpasolve(eqn, x1)
  댓글 수: 1
Vincent Nent
Vincent Nent 2023년 7월 2일
Well it can be so easy. Thank you very much.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by