ans = Empty sym: 0-by-1 error in solving equation
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
John D'Errico
am 18 Jan. 2023
Bearbeitet: John D'Errico
am 18 Jan. 2023
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 Kommentare
Torsten
am 18 Jan. 2023
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 Kommentare
Nikhilesh
am 18 Jan. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!