How can I Solve This Non Linear Parametrical System?

Hi, I tried to solve this equation but Matlab answered this. How can I solve? Thank you
>> syms x y z p r
>> [xAns yAns zAns] = solve([(-1+((1-p)^2))*x + (1-p)*r*y + p^(2)*z, 2*p(1-p)*x +((1-p)*(1-r)+r*p-1)*y + (1-r)*p*z, p^(2)*x + 2*r*(1-r)*y + (((1-r)^2) - 1)*z],[x y z])
Error using sym/subsindex (line 825)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic
variables, and function body must be sym expression.
Error in sym/subsref (line 870)
R_tilde = builtin('subsref',L_tilde,Idx);

 Accepted Answer

Thank you very much but now the problem changed and Matlab answered me this
[xAns yAns zAns] = solve([(-1+((1-p)^2))*x + (1-p)*r*y + r^(2)*z, 2*p*(1-p)*x +((1-p)*(1-r)+r*p-1)*y + ((1-r)^(2))*r*z,( p^(2))*x + p*(1-r)*y + (((1-r)^2) - 1)*z,x+y+z-1],[x y z])
xAns =
Empty sym: 0-by-1
yAns =
Empty sym: 0-by-1
zAns =
Empty sym: 0-by-1

9 Comments

syms x y z p r
eqn = [(-1+((1-p)^2))*x + (1-p)*r*y + r^(2)*z, 2*p*(1-p)*x +((1-p)*(1-r)+r*p-1)*y + ((1-r)^(2))*r*z,( p^(2))*x + p*(1-r)*y + (((1-r)^2) - 1)*z,x+y+z-1]);
sol = solve(eqn);
xAns = sol.x
yAns = sol.y
zAns = sol.z
You were having a problem because you were trying to solve 5 equations for 3 unknowns.
MATLAB finds 5 solutions each with specific numeric values. My calculation is that there are at least 5 families of solutions, one of which is specific numbers, but the other 4 of which involve at least one free parameter, such as p = 1, r = 1, x = 1/2-(1/2)*y, y = y, z = 1/2-(1/2)*y
sol = solve(eqn, 'returnconditions', true);
will give you a set of parameterized solutions:
>> [sol.x,sol.y,sol.z,sol.p,sol.r]
ans =
[ 1 - z1, z1, 0, 0, 0]
[ 0, 1 - z1, z1, 0, 0]
[ 0, -1, 2, 3, -1]
[ 1 - z2 - z1, z1, z2, 0, 0]
[ z1, 1 - 2*z1, z1, 1, 1]
[ 1, 0, 0, 0, z1]
[ 0, 0, 1, z1, 0]
Last thing, if I would have the solution with the 2 free parameters p and r?
If you look at the above list from the returnconditions version, you can see that the first 5 are all for specific p and r. The last two are for free parameters p and r. They can be read as:
(This is not a correct interpretation interpretation of the equations; see below. I leave it in for purposes of the conversation.)
x = r; y = 0; z = 0; p = 0; r free
and
x = 0; y = 0; z = p; p free; r = 0;
yes, I meant, the perfect solution to my problem (a probability one) would be with both p and r parameters as p = t and r = s with t,s in (0,1)
(This is not a correct interpretation interpretation of the equations; see below. I leave it in for purposes of the conversation.)
x = s; y = 0; z = 0; p = 0; r = s;
x = 0; y = 0; z = t; p = t; r = 0;
are the two parameterized solutions. There are also solutions for some particular t and s, as indicated in the table above.
Sorry, I can't explain myself.
Coul Matlab answer me the solution of this system, for example, in this way
x = combination of p and r
y = combination of p and r
z = combination of p and r
p = p
r = r
thank you
Are you looking for code to filter the table
>> [sol.x,sol.y,sol.z,sol.p,sol.r]
ans =
[ 1 - z1, z1, 0, 0, 0]
[ 0, 1 - z1, z1, 0, 0]
[ 0, -1, 2, 3, -1]
[ 1 - z2 - z1, z1, z2, 0, 0]
[ z1, 1 - 2*z1, z1, 1, 1]
[ 1, 0, 0, 0, z1]
[ 0, 0, 1, z1, 0]
to automatically locate the entries in which p or q are not constant? In other words, code to isolate down to the last two of those rows?
There are two solutions, which I mis-stated above
x = 0*p + 0*r + 1; y = 0*p + 0*r + 0; z = 0*p + 0*r + 0; 0; r
x = 0*p + 0*r + 0; y = 0*p + 0*r + 0; z = 0*p + 0*r + 1; p; 0;
There are no solutions for arbitrary p and r.
You can solve your equations incrementally, one equation at a time, first one for x, substitute that result into the second, solve for y, and so on. The solution for y (second one) is already conditional, valid only for some combinations of p and r. The substituted third equation becomes
(r*z*(r + p*r^2 - r^2 - 1))/(p - 1)
which features z as a constant multiple, and so has a general solution of z = 0. This forces specific values for x and y, independent of p and q.
Yes, I was searching for this. Now its all clear.
Thank you very much for the patience.

Sign in to comment.

More Answers (2)

Community Treasure Hunt

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

Start Hunting!