Error in command for partial differentiation

1 次查看(过去 30 天)
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!

请先登录,再进行评论。


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 CenterFile Exchange 中查找有关 Formula Manipulation and Simplification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by