Finding Solution to Inequality in Matlab
8 次查看(过去 30 天)
显示 更早的评论
I have a system of five equations. As below
syms x y z v w q beta rho theta lambda b tau
eqn1 = x == q*(2*rho/(1-lambda) + beta*y) + (1-q)*((1-theta)*(1-tau)/(1-lambda)+beta*z);
eqn2 = y == q*beta*v + (1-q)*(b*(1-theta)/(1-lambda)+beta*z);
eqn3 = v == q*(2*rho/(1-lambda)+ beta*y) + (1-q)*(b*(1-theta)/(1-lambda)+beta*z);
eqn4 = z == (x + w)/2;
eqn5 = w == q*beta*y + (1-q)*((1-tau)*(1-theta)\(1-lambda)+ beta*z);
I want to find the solution for x, in terms of q, beta, rho, theta, lambda, b and tau.
sol = solve([eqn1, eqn2, eqn3, eqn4, eqn5], [x, y, z, w, v]);
sol.x
After that, I want to find the solution to the following inequality
eqn6 = (1-tau)*(1-theta)/((1-beta)*(1-lambda))> sol.x;
This is where the problem begins. When I run the following command:
solution = solve (eqn6, theta);
I get the following error message:
Warning: Unable to find explicit solution. For options, see help. > In sym/solve (line 317)
In dynamic_model_8 (line 13)
I get that these equations are complex, but is there a way to get matlaf to find the result?
Thanks in advance.
0 个评论
回答(3 个)
Torsten
2023-10-13
编辑:Torsten
2023-10-13
I don't understand the result, but there is some output from the symbolic toolbox.
As you can see, the numerator of sol.x is a linear function of theta and the denominator does not contain theta.
Thus the whole thing boils down to determine the zero of a linear function - I'd do it using pencil and paper considering several cases (tau < 1, tau > 1, beta < 1, beta > 1, lambda < 1, lambda > 1) and combinations of these.
I changed
eqn5 = w == q*beta*y + (1-q)*((1-tau)*(1-theta)\(1-lambda)+ beta*z);
to
eqn5 = w == q*beta*y + (1-q)*((1-tau)*(1-theta)/(1-lambda)+ beta*z);
I think it was a typo.
syms x y z v w q beta rho theta lambda b tau
eqn1 = x == q*(2*rho/(1-lambda) + beta*y) + (1-q)*((1-theta)*(1-tau)/(1-lambda)+beta*z);
eqn2 = y == q*beta*v + (1-q)*(b*(1-theta)/(1-lambda)+beta*z);
eqn3 = v == q*(2*rho/(1-lambda)+ beta*y) + (1-q)*(b*(1-theta)/(1-lambda)+beta*z);
eqn4 = z == (x + w)/2;
eqn5 = w == q*beta*y + (1-q)*((1-tau)*(1-theta)/(1-lambda)+ beta*z);
sol = solve([eqn1, eqn2, eqn3, eqn4, eqn5], [x, y, z, w, v]);
sol.x
[N,D] = numden(sol.x);
collect(N,theta)
eqn6 = (1-tau)*(1-theta)/((1-beta)*(1-lambda)) - sol.x > 0;
solution = solve(eqn6, theta)
0 个评论
John D'Errico
2023-10-13
Simple enough. I'll just work with eqn6 here.
syms tau beta lambda theta Solx
eqn6 = (1-tau)*(1-theta)/((1-beta)*(1-lambda))> Solx;
solve(eqn6,theta,'returnconditions',true)
2 个评论
Dyuman Joshi
2023-10-13
编辑:Dyuman Joshi
2023-10-13
Also, as every other division operator used is a backslash or rdivide, ./, there seems to be a typo here -
% v
qn5 = w == q*beta*y + (1-q)*((1-tau)*(1-theta)\(1-lambda)+ beta*z);
Walter Roberson
2023-10-13
Turn inequalities into equalities by adding a positive (or non-negative) variable representing how much more one side is compared to the other.
syms x y z v w q beta rho theta lambda b tau
eqn1 = x == q*(2*rho/(1-lambda) + beta*y) + (1-q)*((1-theta)*(1-tau)/(1-lambda)+beta*z);
eqn2 = y == q*beta*v + (1-q)*(b*(1-theta)/(1-lambda)+beta*z);
eqn3 = v == q*(2*rho/(1-lambda)+ beta*y) + (1-q)*(b*(1-theta)/(1-lambda)+beta*z);
eqn4 = z == (x + w)/2;
eqn5 = w == q*beta*y + (1-q)*((1-tau)*(1-theta)\(1-lambda)+ beta*z);
sol = solve([eqn1, eqn2, eqn3, eqn4, eqn5], [x, y, z, w, v]);
sol.x
syms Excess positive
eqn6 = (1-tau)*(1-theta)/((1-beta)*(1-lambda)) - Excess == sol.x
solution = solve (eqn6, theta)
sympref('AbbreviateOutput', 0)
collect(simplify(solution, 'steps', 50), Excess)
6 个评论
Sam Chak
2023-10-14
Thanks @Walter Roberson. I guess that your tests further reinforce that the 'collect()' function only works on strictly polynomials, , but not on rational functions, even though they are quotients of two polynomials, .
Walter Roberson
2023-10-14
If you look at coeffs4 the denominator is collected with respect to x: it just isn't as factored as for the coeffs3 case. It did not fail to collect: it just didn't fully factor after collecting, even though fully factoring is not a documented outcome in the first place.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!