I am experiencing a weird error in Matlab that is not prone to being solved with internet research, and it comes up when trying to solve the following equation for the variable, S
:
-(W-S)^(y-1) + d*p*(1+f+w1*(r1-f))^y + d*(1-p)*(1+f+w1*(r2-f))^y == 0
The code I use is
syms W S y d p r1 r2 f positive
eqn = -(W-S)^(y-1) + d*p*(1+f+w1*(r1-f))^y + d*(1-p)*(1+f+w1*(r2-f))^y == 0
solve(eqn, S)
and the error, along with incorrect answer, that I get is
Warning: The solutions are parameterized by the symbols: k.
To include parameters and conditions in the solution,
specify the 'ReturnConditions' option.
> In solve>warnIfParams (line 500)
In solve (line 356)
Warning: The solutions are valid under the following
conditions: 1 < y & in(k, 'integer') & k*pi < (pi/2 +
angle(d*p*(f - w1*(f - r1) + 1)^y - d*(p - 1)*(f - w1*(f -
r2) + 1)^y)/(2*(y - 1)))*(y - 1) & 0 < W - exp(-(k*pi*2i)/(y
- 1))*(-d*((p - 1)*(f - w1*(f - r2) + 1)^y - p*(f - w1*(f -
r1) + 1)^y))^(1/(y - 1)) & angle(d*p*(f - w1*(f - r1) + 1)^y
- d*(p - 1)*(f - w1*(f - r2) + 1)^y) <= 2*k*pi + pi*(y - 1) |
y < 1 & in(k, 'integer') & (pi/2 + angle(d*p*(f - w1*(f - r1)
+ 1)^y - d*(p - 1)*(f - w1*(f - r2) + 1)^y)/(2*(y - 1)))*(y -
1) < k*pi & 0 < W - exp(-(k*pi*2i)/(y - 1))*(-d*((p - 1)*(f -
w1*(f - r2) + 1)^y - p*(f - w1*(f - r1) + 1)^y))^(1/(y - 1))
& 2*k*pi + pi*(y - 1) <= angle(d*p*(f - w1*(f - r1) + 1)^y -
d*(p - 1)*(f - w1*(f - r2) + 1)^y).
To include parameters and conditions in the solution,
specify the 'ReturnConditions' option.
> In solve>warnIfParams (line 507)
In solve (line 356)
ans =
W - exp(-(pi*k*2i)/(y - 1))*(d*p*(f - w1*(f - r1) + 1)^y - d*(p - 1)*(f - w1*(f - r2) + 1)^y)^(1/(y - 1))
Thing is, I can solve this by hand with no problem and get the answer, which even Wolfram Alpha agrees with, so I know Matlab or I are experiencing a hiccup somewhere:
Where am I going wrong in my code?