i have following equation. Totally there are two equations with two unknowns "x, y". But when I run it takes infinite time to solve and finally shows error. Where am I going wrong?

1 view (last 30 days)
iter=1;
Patm=100000;
presB=Patm*ones(iter,1);
PSB=Patm*ones(iter,1);
PT=Patm*ones(iter,1);
AT=0.0071094;
AB=0.010010;
GAMMA=1.4;
rhoS=1.2041;
m=23.5;
g=9.8;
T=20+273;
R=287.05;
ODSB=0.122;
IDSB=0.0956;
ASB=pi*(ODSB^2-IDSB^2)/4;
v=5;
displ_f=0;
dt=0.001;
i=1
displ(i,1)=displ_f+(v*dt);
displ_f=displ_f+10;
displ(i,2)=v;
v=v+10;
PT(i,1)=Patm;
syms x y
eqn1 = (x*AB)-(y*ASB)-(PT(i,1)*AT)-(m*g)==0;
eqn2 = (rhoS*(GAMMA-1)/GAMMA)*((((GAMMA-1)/GAMMA)*R*T)+((displ(i,2))^2/2)-((1/2)*((x*AB*displ(i,2))/(R*T*ASB*rhoS))^2))-y==0
sol = solve([eqn1, eqn2], [x, y]);
xsol = sol.x
ysol = sol.y

Accepted Answer

John D'Errico
John D'Errico on 6 Feb 2019
Edited: John D'Errico on 6 Feb 2019
Seriously? It works fine for me. Admittedly, I could probably have solved those equations using pencil and paper almost as easily and as quickly.
tic,sol = solve([eqn1, eqn2], [x, y]);toc
Elapsed time is 0.337176 seconds.
double(sol.x)
ans =
-1075050938.74634
97749.2548315201
double(sol.y)
ans =
-2385329642.21121
8251.65028261729
My guess is the problem that took infinitely much time and then failed was a different problem than what you showed.
People often do this. They get confused. They have some vriables with other definitions than they think. They run some code that does something strange, BECAUSE they did not actually do what they thought they were doing. Then they rush online, claiming that the code they show does something completely insane.
So, if you are not able to do this, then perhaps you need to get used to checking your results more carefully. Check what goes into your results. If necessary, do the newbie thing, and start your scripts with a call to clear, or more strongly yet:
clear all
Don't just throw together a mass of code, run it, then expect that the result that comes out the end will make sense to you, without knowing that every intermediate step was correct, without knowing positively what went into your computations.

More Answers (0)

Products


Release

R2013a

Community Treasure Hunt

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

Start Hunting!