Borrar filtros
Borrar filtros

undefined variable problem using vpasolve

5 visualizaciones (últimos 30 días)
Vincent Nent
Vincent Nent el 2 de Jul. de 2023
Comentada: Vincent Nent el 2 de Jul. de 2023
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 comentario
Walter Roberson
Walter Roberson el 2 de Jul. de 2023
syms x1 before you define g1 since g1 and g2 use x1

Iniciar sesión para comentar.

Respuesta aceptada

Shantanu Dixit
Shantanu Dixit el 2 de Jul. de 2023
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)

Más respuestas (0)

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by