ans = Empty sym: 0-by-1 error in solving equation
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to solve a equation for a small project but experiencing
syms x
y= (0:1:100)
avd=5
s = 0.25
paco2=40
r= 0.8
hb=14
pb=740
eqn = ((hb*(((((pb-47)*y-paco2/r).^3+150*((pb-47)*y-paco2/r)).^(-1)*23400)+1).^(-1)*1.34)+((pb-47)*y-paco2/r)*0.0031)- (hb*(((x.^3+150*x).^(-1)*23400)+1).^(-1)*1.34+(x*0.0031))==(s/(1-s))*avd
solve(eqn, x)
and get this result
ans =
Empty sym: 0-by-1
댓글 수: 0
답변 (3개)
John D'Errico
2023년 1월 18일
편집: John D'Errico
2023년 1월 18일
So many times I see this mistake made. I can understand where it comes from. But it gets MATLAB (actually solve) confused.
When you define y in advance as a vector, then the symbolic toolbox thinks you have 101 equations, but only the 1 unknown x. Solve now fails. Instead, you need to leave y as an unknown parameter, and try to solve for x as a function of y.
syms x
% y= (0:1:100) DON'T DO THIS IN ADVANCE!!!!!!!
% instead, leave y as a symbolic parameter. You will subs in that vector at
% the end.
syms y
avd=5;
s = 0.25;
paco2=40;
r= 0.8;
hb=14;
pb=740;
eqn = ((hb*(((((pb-47)*y-paco2/r).^3+150*((pb-47)*y-paco2/r)).^(-1)*23400)+1).^(-1)*1.34)+((pb-47)*y-paco2/r)*0.0031)- (hb*(((x.^3+150*x).^(-1)*23400)+1).^(-1)*1.34+(x*0.0031))==(s/(1-s))*avd
So we have a rather messy expression for x and y together. Before we go any further, it is ALWAYS important to plot everything.
fimplicit(eqn,[-100 100 0 100])
So fimplicit finds some negative solutions for x, and some large positive solutions between 80 and 100, all depending on the value of y.
If y has a known value, we can clear the fractions, and find what is effectively a 4th degree polynomial in x.
xsol = solve(eqn,x,'returnconditions',true)
xsol.x
Unfortunately, we cannot yet resolve the roots, until we substitute in for y. So it is only now that we provide the values for y. For example...
vpa(subs(xsol.x,y,2))
So, as I said, a negative root, and a large positive root, and two complex roots.
plot(0:100,double(subs(xsol.x(1),y,0:100)))
xlabel y
ylabel x
Note that the abscissa here is the value of y, and the ordinate (y axis) is the computed value of x, for the first root.
댓글 수: 0
Torsten
2023년 1월 18일
syms x y
Y = 0:1:100;
avd=5;
s = 0.25;
paco2=40;
r= 0.8;
hb=14;
pb=740;
eqn = ((hb*(((((pb-47)*y-paco2/r).^3+150*((pb-47)*y-paco2/r)).^(-1)*23400)+1).^(-1)*1.34)+((pb-47)*y-paco2/r)*0.0031)- (hb*(((x.^3+150*x).^(-1)*23400)+1).^(-1)*1.34+(x*0.0031))-(s/(1-s))*avd==0;
[N,D] = numden(lhs(eqn));
for i=1:numel(Y)
sol{i} = vpa(root(subs(N,y,Y(i))));
end
댓글 수: 0
Nikhilesh
2023년 1월 18일
It seems you are trying to iterate over the value of y and solve for each value of x.
It would be beneficial if you can use a for loop which iterate over values of y (1-100) and place the equation inside the for loop.
for y=0:100
eqn = ((hb*(((((pb-47)*y-paco2/r).^3+150*((pb-47)*y-paco2/r)).^(-1)*23400)+1).^(-1)*1.34)+((pb-47)*y-paco2/r)*0.0031)- (hb*(((x.^3+150*x).^(-1)*23400)+1).^(-1)*1.34+(x*0.0031))==(s/(1-s))*avd
S=solve(eqn, x)
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!