Solve for two equation with two unknown variables

clc
clear
a=436*10^-6;
rho=2.2*10^-5;
k=2.6;
Z=a^2/(rho*k);
Tcevre=-5+273;
ZTcevre=Z*Tcevre;
Ts=408.15;
Tsy=Ts/Tcevre;
h1=106.6575;
A1=0.04*0.04;
h2=53.3320;
A2=37*10^-4;
Nh=(h1*A1)/(0.9*h2*A2);
syms x y
for Nk=0.1:0.1:1
for Rr=1:0.1:2
Eq1= Nh*(Tsy-x)==(((ZTcevre*(x-y)*x)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
Eq2=(y-1)/Nk ==(((ZTcevre*(x-y)*y)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
[X,Y]=solve(Eq1,Eq2,x,y)
pretty(X)
% eqns = [Eq1,Eq2];
% S=solve(eqns, [x y]);
% S.x
% S.y
end
end
I have 4 unknowns and I'm converting two equations with two for loop to two. Then I used [X, Y] = solve (Eq1, Eq2, x, y) to solve these two, but when I wanted to find a numeric value, the terms root and Z ^ 3 came up. What command can I use or provide a code to be a numeric value? Could you help?

 Accepted Answer

Use vpasolve (link), specifically:
[X,Y]=vpasolve(Eq1,Eq2,x,y)

7 Comments

Daryun’s Answer moved here:
syms x y
for Nk=0.1:0.1:1
for Rr=1:0.1:2
Eq1= Nh*(Tsy-x)==(((ZTcevre*(x-y)*x)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
Eq2=(y-1)/Nk ==(((ZTcevre*(x-y)*y)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
[X,Y]=vpasolve(Eq1,Eq2,x,y)
Ty1=max(X)
Ty2=max(Y)
T=table(Ty1,Ty2)
filename='exceltablo.xlsx';
writetable(T,filename,'Sheet',1,'Range','A1')
end
end
I used the code and reached the right result. Thank you.
X =
-6.7593734083447082055291165178641
1.2210399341020178731175349017453
2.6728447628426545586770359583302
From the results here I want to get the values from 1 to 2. And I want to show these values in the excel table. But the code below doesn't provide it to me? What can I do?
Ty1=max(X)
Ty2=max(Y)
T=table(Ty1,Ty2)
filename='exceltablo.xlsx';
writetable(T,filename,'Sheet',1,'Range','A1')
I would save ‘Ty1’ and ‘Ty2’ as arrays, convert them to tables, then create your unified table by concatenating them horizontally:
a=436E-6;
rho=2.2E-5;
k=2.6;
Z=a^2/(rho*k);
Tcevre=-5+273;
ZTcevre=Z*Tcevre;
Ts=408.15;
Tsy=Ts/Tcevre;
h1=106.6575;
A1=0.04*0.04;
h2=53.3320;
A2=37E-4;
Nh=(h1*A1)/(0.9*h2*A2);
syms x y
Nkv = 0.1:0.1:1;
Rrv = 1:0.1:2;
for k1 = 1:numel(Nkv)
Nk = Nkv(k1);
for k2 = 1:numel(Rrv)
Rr = Rrv(k2);
Eq1= Nh*(Tsy-x)==(((ZTcevre*(x-y)*x)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
Eq2=(y-1)/Nk ==(((ZTcevre*(x-y)*y)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
[X,Y]=vpasolve(Eq1,Eq2,x,y);
Ty1(k1,k2) = double(max(X));
Ty2(k1,k2) = double(max(Y));
end
end
T1 = array2table(Ty1)
T2 = array2table(Ty2)
T = [T1,T2];
Experiment to get the result you want.
Daryun’s Answer moved here:
Okay, I'il try. If I find anything, I'il write. And if I can't, I'm a writer. Thank you so much:)
My variation on your code should work. It did when I tested it, although I am not certain what result you want.
If my Answer helps you solve your problem, please Accept it!
I accepted:) and an additional code :)
clc;
clear all;
a=436*10^-6;
rho=2.2*10^-5;
k=2.6;
Z=a^2/(rho*k);
Tcevre=-5+273;
ZTcevre=Z*Tcevre;
Ts=408.15;
Tsy=Ts/Tcevre;
h1=106.6575;
A1=0.04*0.04;
h2=53.3320;
A2=37*10^-4;
Nh=(h1*A1)/(0.9*h2*A2);
syms x y
Nkv = 0.1:0.1:1;
Rrv = 1:0.1:2;
T=[];
for k1 = 1:numel(Nkv)
Nk = Nkv(k1);
for k2 = 1:numel(Rrv)
Rr = Rrv(k2);
Eq1= Nh*(Tsy-x)==(((ZTcevre*(x-y)*x)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
Eq2=(y-1)/Nk ==(((ZTcevre*(x-y)*y)/(Rr+1))-((ZTcevre*(x-y)^2)/(2*(Rr+1)^2))+(x-y));
[X,Y]=vpasolve(Eq1,Eq2,x,y);
T= [T ; max(double(X)), max(double(Y))];
filename='exceltablo.xlsx';
end
end
xlswrite(filename,T,1,'A1');
Hi. I am also trying to solve two equations of 2 unkowns but unfortunately I am not getting the required solutions by using vpasolve. There may be infinite solutions but I needed the most converging solution. Here is the code. Can you please tell me how to find the roots. Thank you.
Y1=0.0125;l1=0.0105;be=0.0675;
lambda= [0.0426 0.0400 0.0405 0.0420];
syms Y2 l2;
t1e=((2*pi)/lambda(1))*l1;
t2e=((2*pi)/lambda(1))*l2;
eq1=2*Y1*tan(t1e)+Y2*tan(t2e)==0;
eq2= Y1*(t1e-((sin(t1e)*cos(t1e))/(sin(t2e)*cos(t2e))))==be;
E=[eq1,eq2];
S=vpasolve(E,Y2,l2);

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!