Error in command for partial differentiation

1 回表示 (過去 30 日間)
Sergio Manzetti
Sergio Manzetti 2017 年 7 月 14 日
コメント済み: Walter Roberson 2017 年 12 月 29 日
Hi, I am trying to run this simple command:
y*(x*(exp(-i*(x+y)) - diff((exp(-i*(x+y)), x)) - x*diff((exp(-i*(x+y)), y) + diff((exp(-i*(x+y)), x, y)
however MATLAB doesn't take it and says:
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
However, the brackets are balanced...

回答 (3 件)

Jan
Jan 2017 年 7 月 14 日
編集済み: Jan 2017 年 7 月 14 日
Seriously? Matlab tells you clearly, that the parenthesis are not balanced and you do not believe it?
c = ['y*(x*(exp(-i*(x+y)) - diff((exp(-i*(x+y)), x)) - ', ...
'x*diff((exp(-i*(x+y)), y) + diff((exp(-i*(x+y)), x, y)']
sum(c == '(') % >> 16
sum(c == ')') % >> 12
There are 4 unclosed parenthesis. Ups. I recommend to trust Matlab's error messages.
  3 件のコメント
Tam Ho
Tam Ho 2017 年 12 月 29 日
I ran this code:
syms theta %create symbolic variable theta
assume(theta,'real') %theta is real
f = fit_v2; %calling our fitted polynomials
g = diff(f,theta);
g0=solve(g,theta);
double(g0);
I get this error:
Error in sym (line 215)
S.s = tomupad(x);
Error in sym/privResolveArgs (line 988)
argout{k} = sym(arg);
Error in sym/diff (line 21)
args = privResolveArgs(S,varargin{:});
Error in code (line 54)
g = diff(f,theta);
please help! Thanks!
Walter Roberson
Walter Roberson 2017 年 12 月 29 日
What is fit_v2 ?

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


Sergio Manzetti
Sergio Manzetti 2017 年 7 月 14 日
John ,please see closer, I have removed one redundant bracket after the y at the beginning, otherwise, it is fine:
y*x*(exp(-i*(x+y)) - diff((exp(-i*(x+y)), x)) - x*diff((exp(-i*(x+y)), y) + diff((exp(-i*(x+y)), x, y))
Nothing is missing here or superfluous

Sergio Manzetti
Sergio Manzetti 2017 年 7 月 14 日
編集済み: Walter Roberson 2017 年 12 月 29 日
Have a look at this short example:
>> diff((exp(-i*(x+y)), x))
diff((exp(-i*(x+y)), x))
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 29 日
diff(exp(-i*(x+y)), x)
or
diff((exp(-i*(x+y))), x)
If you examine
diff((exp(-i*(x+y)), x))
you will see that the first argument is
(exp(-i*(x+y)), x)
which is an invalid sequence, since MATLAB does not permit expression comma expression inside anything other than [] or {} . You are also not passing a second argument to diff()

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

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by