To express a differential equation in standard form in Matlab, we can use the function diff
to take symbolic derivatives of the dependent variable(s) with respect to the independent variable.
For example, consider the differential equation:
y'' - 2y' + y = 0
To express this equation in standard form, we first define the dependent variable y and the independent variable x as symbolic variables:
main.m10 chars2 lines
Then, we use diff
to take the first and second derivatives of y with respect to x:
main.m43 chars3 lines
Finally, we substitute these derivatives and the original function y into the differential equation, and simplify:
main.m52 chars3 lines
This returns the differential equation in standard form:
y(x) - 2*diff(y(x), x) + diff(y(x), x, x) = 0
gistlibby LogSnag