Error in command for partial differentiation

1 Ansicht (letzte 30 Tage)
Sergio Manzetti
Sergio Manzetti am 14 Jul. 2017
Kommentiert: Walter Roberson am 29 Dez. 2017
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...

Antworten (3)

Jan
Jan am 14 Jul. 2017
Bearbeitet: Jan am 14 Jul. 2017
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 Kommentare
Tam Ho
Tam Ho am 29 Dez. 2017
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 am 29 Dez. 2017
What is fit_v2 ?

Melden Sie sich an, um zu kommentieren.


Sergio Manzetti
Sergio Manzetti am 14 Jul. 2017
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 am 14 Jul. 2017
Bearbeitet: Walter Roberson am 29 Dez. 2017
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 Kommentar
Walter Roberson
Walter Roberson am 29 Dez. 2017
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()

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Formula Manipulation and Simplification finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by