Solving for Variables contained an interval
8 views (last 30 days)
Paul on 11 Mar 2023
Referring to the form of y given in this comment:
syms x real
y = sin(x)*(2*cos(x) - 1) / ((1 + 2*cos(x)) * (1 - cos(x)))
fplot(y,[0 1]) % don't know why the plot shows up below and not here?
Find the inverse function
fx = (finverse(y))
Sub so that we get a function of the form where we input y and output x
syms yy real
fx(yy) = subs(fx,x,yy)
Imaginary part is zero
So all we need is the real part
fx = real(simplify(fx,100))
Check a value
axis([0 0.1 0 50])
More Answers (2)
Askic V on 11 Mar 2023
Edited: Askic V on 11 Mar 2023
fun = @(x) (sin(x) .* (2.* cos(x) - 1)) ./ (1 + 2 .* cos(x)); % function
x0 = [0.1 2]; % initial interval
x = fzero(fun,x0)
t = linspace(0,2);
y = fun(t);
The function has value zero at x = 0, and the next one is at 1.0472. Therefore in the interval between 0 and 1 there is only a solution at 0.
John D'Errico on 11 Mar 2023
Edited: John D'Errico on 11 Mar 2023
y = (sin(x) * (2* cos(x) - 1)) / (1 + 2 * cos(x));
xsol = solve(y == 0)
There are only three primary solutions.
xsol = solve(y == 0,'returnconditions',true)
As you can see, now solve treturns a more complete result.
So, for integer k, the set of all solutions is one of those given in xsol.x, parameterized by the integer value of k.
That first positive solution is at pi/3, whhich falls just slightly outside of the interval [0,1]. So the only solution in that interval is 0 itself.
And that is exactly what @Askic V told you. Best to just use fzero.