problem using variables solving trigonometric equation with "solve('...')

7 ビュー (過去 30 日間)
Flavien
Flavien 2012 年 2 月 9 日
Hi all,
I am trying to solve a trigonometric equation. It works just fine if I put a number in the solver, but return an error if I type a variable.
For example:
syms x;
solve('sin(x) = x -1')
works perfectly.
However, when I try:
syms x;
a = 1;
solve('sin(x) = x -a')
I get the error:
Warning: Explicit solution could not be found.
> In solve at 81
ans =
[ empty sym ]
As the equation in integrated in some code, it is of no use if I cannot solve it with the variable. If someone has an idea it would be great!
Cheers, Flavien

回答 (2 件)

Aaditya Kalsi
Aaditya Kalsi 2012 年 4 月 1 日
It may be better to define 'a' as a symbolic variable and not a double.
syms x;
a = sym('1');
f = sin(x) -x + a;
myVal = solve(f, x);
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 4 月 1 日
Defining it as a symbolic variable doesn't matter.
a = 1
f = sin(x) - x + a;
myVal = solve(f,x);

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


Walter Roberson
Walter Roberson 2012 年 4 月 1 日
syms x;
a = 1;
solve(subs(sym('sin(x) = x -a')));
The MATLAB-level value of a variable is not used within a quoted string (such as you were solving for) unless you use the subs() operation to request the substitution.

カテゴリ

Help Center および File ExchangeEquation Solving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by