0

my question relates to the Symbolic Math Toolbox from Matlab. I have the following code:

syms x x_0 u delta sigma_1
mu = sym ('mu(x)');
sigma_u = sym ('sigma(u)');
sigma = sym ('sigma(x)');
f = int (1/sigma_u, u, x_0, x);
df = subs(diff(f,x))
df_2 = subs(diff (f,x,2))
L = subs(mu*df+1/2*sigma^2*df_2)

The result of L is corect

L =

mu(x)/sigma(x) - diff(sigma(x), x)/2

However, for further derivations and for simplicity, I would like to define

sigma_1 = sym('diff(sigma,x)'); 

or in a similar way such as to get as result for

L =

mu(x)/sigma(x) - sigma_1(x)/2

Basically, I would like to store under a name the symbolic expression diff(sigma(x),x) such that Matlab knows that when it gets this result in a expression, to poste the name sigma_1 (x) instead of diff(sigma(x),x)

  • `f` is defined by means of an integral the Matlab is not able to evaluate; is that ok or not? – fpe Jan 28 '13 at 21:55
  • Hello. no, that is not the problem, Matlab cannot anyway evaluate the integral since the function sigma(u) is not explicitly defined. Matlab does a great job in applying Leibniz Rule in computing L (through df and df_2). However, I would just like that instead of having in the answer – user1545441 Jan 28 '13 at 22:09
  • diff(sigma(x), x) to have a name for the first serivative like sigma_1 which should stand for the first derivative of sigma wrt x and mostly I would like that sigma_1 to appear always in the program instead of diff(sigma(x), x). Subsequently, I would like to define similarly further higher order derivatives of the function sigma. Thank you – user1545441 Jan 28 '13 at 22:12
  • If you have the output it should not be too hard to replace this everywhere, why not simplify it afterwards? I think that what you ask may not be possible as you could also define sigma_2 in the same way and matlab would be lost. – Dennis Jaheruddin Feb 06 '13 at 10:33

1 Answers1

0

Yes it is possible, you can use subs(L, 'diff(sigma(x),x)', 'sigma_1(x)'). Note to make the substitution work, the second input of subs must be exactly like what you want to replace; hence it cannot be 'diff(sigma, x)' which lacks the (x) behind the sigma.

Also note that here is a similar question for which I provided a more complete solution (they asked the question after yours, but I read theirs first).

Community
  • 1
  • 1
Strategy Thinker
  • 343
  • 1
  • 3
  • 15