Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do partial derivatives in Octave

Tags:

I'm working on a code in a group for a class. One of the biggest obstacles is figuring out a code to do partial derivatives. Octave is similar to Matlab syntax wise but it does not do symbols "sym". I'm kinda stuck as to how to go about doing a partial derivative in the program. It has to be done in Octave, it cannot be done in Matlab.

like image 622
user3797544 Avatar asked May 04 '16 21:05

user3797544


1 Answers

Basically just parroting what @rayryeng has said in his comment, but a small self-contained example to find the partial derivative of y(x, z) = x^2 + z^2 with respect to x:

pkg load symbolic
syms x z
y = x^2 + z^2
diff(y, x)

Gives the result:

ans = (sym) 2*x

Which is the correct partial derivative of y with respect to x. Note that to get this to work you will have to install the symbolic package. I found that I also needed to have the python package SymPy installed. There are some helpful instructions here.

like image 116
kabdulla Avatar answered Sep 28 '22 03:09

kabdulla