formation of a function like in Mathematica
Show older comments
Hello, I am new user in Matlab, My question is that how can i form a function in editor file like we can make in Mathematica like
F[n_] := ComplexExpand[Im[etp[n]/(et[n] - (x + y I))]]
Also Is there any equivalent command for
ComplexExpand
in Matlab? Thanks
1 Comment
hparacha777
on 6 Aug 2015
Edited: hparacha777
on 6 Aug 2015
Hi, you can write the function in Matlab Editor as:
function [out1, out2, ...] = myfun(in1, in2, ...)
Just save the file with the name of the function. Hope it helps.
Answers (1)
Walter Roberson
on 5 Aug 2015
f = @(n) ComplexExpand(imag(etp(n)/(et(n) - (x + y * i))))
however, ComplexExpand, etp, and et are not defined for MATLAB.
Mathematica's ComplexExpand is a non-trivial symbolic process so to get it right you would need to be working with the Symbolic Toolbox. At the moment I do not see an equivalent routine in the Symbolic Toolbox. In the programming language Maple that the Symbolic Toolbox has many similarities to, the routine would be named evalc(), but MATLAB'S evalc() has nothing to do with that.
7 Comments
Kashif
on 5 Aug 2015
Walter Roberson
on 5 Aug 2015
As you are taking the imaginary part of the function anyhow, you can probably substitute
syms etp etn x y real
syms f(n)
f(n) = simplify(imag(etp(n)/(et(n) - (x + y * i))));
gradient(f(n), [x, y])
Kashif
on 6 Aug 2015
Walter Roberson
on 6 Aug 2015
I am not positive this will work but try
syms et(n)
n1 = n/8;
n2 = n + n/8;
feval(symengine,'_assign', et(n1), 8.33663 + 6.8417*1i);
feval(symengine,'_assign', et(n2), 0.641945 - 0.526831*1i);
then see what
et(n1), et(n2), et(n)
return
If not then.... ummm, maybe
syms et n
evalin(symengine, 'et := N -> piecewise([N=n/8, 8.33663 + 6.8417*1i], [N=n+n/8, 0.641945 - 0.526831*1i], [Otherwise, procname(N)]);');
A bit tricky here is the unassigned behaviour for et at values other than n/8 and n+n/8.
You asked for the partial derivative with respect to both variables. I interpreted that as gradient. Perhaps you wanted
diff(f(n),x,y)
Walter Roberson
on 6 Aug 2015
You are not likely to get those any time soon. MATLAB has a limited interface subset to the Symbolic Toolbox ('MuPAD') which is more powerful.
I was assisting you under the assumption that you wanted to make something work. The primary barrier to making something work is the definition of et and etp as objects that need to recognize two specific inputs and return specific arbitrary outputs for those two inputs while being meaningfully defined symbolically for the formula with indefinite n.
Kashif
on 8 Aug 2015
Categories
Find more on Operations on Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!