vpasolve gives answers outside the range that I specify
3 views (last 30 days)
Show older comments
My code is the following:
syms E C D V P S A
equation1 = (E - C + 200*D + 3)/V - 5*P - (500*S)/(100*A + 1) - 1/5 == 0
Y = vpasolve( equation1, [E C D V P S A], [0 100;0 100;0 100;0 100;0 100;0 100;0 100] )
Y =
struct with fields:
E: -3.0
C: 0
D: 0
V: 0
P: 0
S: 0
A: 0
But! I have defined the search range to be positive, so why do I keep getting this answer? I cannot do anything to change the outcome.
Also, I am really questioning the usefulness of vpasolve since it can't even give an answer to something like:
syms x y
S = vpasolve([x^2+y^2 == 1],[x y],[0.5 1;0 1])
S.x
S.y
, where I am interested in a solution where x is between 0.5 and 1, which clearly exists! (but not according to Matlab)
2 Comments
Paul
on 15 Jun 2022
Though not stated on the doc page AFAICT, maybe vpasolve needs to have at least the same number of equations as unknowns when specifying init_param. There may be some other restrictions on the equations as well.
This works fine
syms x y
S = vpasolve([x + y == 1; x^2 == y],[x y],[0 1;0 1])
But this doesn't?
syms x y
S = vpasolve(x + y == 1,[x y],[0 1;0 1])
Star Strider
on 15 Jun 2022
I certainly agree that solving one equation in seven unknowns is unlikely to be successful for more than one of them, however the question was about getting a positive result.
Answers (1)
Star Strider
on 14 Jun 2022
One option is to specify conditions on the variables, for example on ‘E’ (and any others you may want) —
syms E C D V P S A
assume(E>=0)
equation1 = (E - C + 200*D + 3)/V - 5*P - (500*S)/(100*A + 1) - 1/5 == 0
Y = solve( equation1, [E C D V P S A] )
Y = vpa(struct2cell(Y),)
I am not certain how much sense this makes in the context of the problem, however it seems to produce the desired result.
.
3 Comments
Star Strider
on 14 Jun 2022
I usually prefer solve and then using vpa on the results, to vpasolve.
I am not certain what you may want to do with the Optimization Toolbox functions, since in general the Symbolic Math Toolbox may be better for problems such as these.
However an easy way to use your equation with them is:
syms E C D V P S A
equation1 = (E - C + 200*D + 3)/V - 5*P - (500*S)/(100*A + 1) - 1/5
eqn1fcn = matlabFunction(equation1, 'Vars',{[E C D V P S A]})
This presents all the variables as elements of the ‘in1’ vector, with:
in1(:,1) = E
...
in1(:,7) = A
in the order of their position in the 'Vars' vector.
.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

