'solve': simple functions throw geteqns lne 404 error

Hello
I am using MATLAB online and the following code throws an error
The same code with ==0 instead of ==1 works fine.
What is the problem?
D
clear all;
clc;
syms x;
[solx, param, cond] = solve(x*cot(x)==1, x, 'ReturnConditions', true);
> In sym/solve (line 317)
In solutionsPS67 (line 4)
Error using sym/solve>getEqns (line 404)
Input argument contains an empty equation or variable.

4 件のコメント

Walter Roberson
Walter Roberson 2020 年 11 月 3 日
syms x;
[solx, param, cond] = solve(x*cot(x)==1, x, 'ReturnConditions', true);
works for me online, just saying that there is no explicit solution.
Denis Bidinost
Denis Bidinost 2020 年 11 月 3 日
Thanks for looking into it,
There are actually solutions for ==1, ==2 etc.. just fplot(x*cot(x), [0 2*pi])
Any value at the right of == seems to throw an error, irrespective of the value
D
Denis Bidinost
Denis Bidinost 2020 年 11 月 3 日
For me it throws:
Warning: Unable to find explicit solution. For options, see help.
> In sym/solve (line 317)
In solutionsPS67 (line 4)
Error using sym/solve>getEqns (line 404)
Input argument contains an empty equation or variable.
Denis Bidinost
Denis Bidinost 2020 年 11 月 3 日
It is actually the following code that makes it throw the error:
syms x;
[solx, param, cond] = solve(x*cot(x)==0.01, x, 'ReturnConditions', true);
assume(cond);
solk = solve(0<solx, solx<2*pi, param);
If I comment the last two lines I am left only with the Warning, it seems the equation
does not solve as expected, something is missing?
Thanks a lot
D

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 4 日

1 投票

solve() is designed to return indefinitely precise solutions whenever it can figure out how.
If it cannot figure out how to calculate a formula for the solution, then if the number of equations matches the number of variables and there are no inequalities, solve() will attempt to find one numeric solution, unless returnconditions was asked for, in which case it will return empty.
With your solution returning empty, (0<solx, solx<2*pi, param) is empty, so you are asking to solve an empty system, which is where the error is coming from.
You should use vpasolve() with a range argument,
vpasolve(x*cot(x)==0.01, x, [0, 2*pi])

1 件のコメント

Denis Bidinost
Denis Bidinost 2020 年 11 月 4 日
Many Thanks
vpasolve is the right function for me, understood

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by