How to define the abstract symbolic of 'f=f(x,y,z)' at Matlab-Smbolic.

6 views (last 30 days)
I have a black-box function of 3-variables : f=f(x,y,z). I would like to define with symbolic the relation of 'f' with 'x','y' and 'z', as the abstract type of mathematics 'f=f(x,y,z)'.
In example, I want to do something like:
syms x y z; _I do not know how to set the symbolic at command line : f=f(x,y,z);
g = x * f + y * f^2 + z; jacobian( g, [x,y,z])
and the expected result will be :
( f + x*(df/dx) + 2*y*f*(df/dx), x*(df/dy) + f^2 + 2*y*f*(df/dy), x*(df/dz) + 2*y*f*(df/dz) + 1)
Thanks.

Answers (2)

Lucas García
Lucas García on 15 Sep 2011
You can do the following:
>> syms x y z;
>> f = sym('f(x,y,z)');
>> g = x * f + y * f^2 + z;
>> jacobian(g, [x,y,z])
ans =
[ x*diff(f(x, y, z), x) + 2*y*f(x, y, z)*diff(f(x, y, z), x) + f(x, y, z), 2*y*f(x, y, z)*diff(f(x, y, z), y) + x*diff(f(x, y, z), y) + f(x, y, z)^2, x*diff(f(x, y, z), z) + 2*y*f(x, y, z)*diff(f(x, y, z), z) + 1]

Andrei Bobrov
Andrei Bobrov on 15 Sep 2011
syms x y z f
g = x * f + y * f^2 + z
g1 = subs(g,f,'f(x,y,z)')
gj = jacobian(g1,[x y z])
for j1 = [x y z],gj = subs(gj,['diff(f(x, y, z), ', char(j1), ')'],['df',char(j1)]); end
out = subs(gj,'f(x, y, z)',f)

Tags

Community Treasure Hunt

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

Start Hunting!