Now we can easily solve the original initial value problem by typing f(t) = dsolve(besselODE, y(1)=1, y(2)=n) Note that we used diff to introduce the symbolic derivatives of y and the = sign to set up a symbolic equation. Now we define the Bessel ODE by typing besselODE = t^2*diff(y,2) + t*diff(y) + (t^2-n^2)*y = 0 Now the dependent ODE variable is declared as a symfun (symbolic function) y(t): syms n y(t) Īfter executing the last command, we can see the symfun y as well as the symbolic variables n and t in the MATLAB workspace. Improving Our Workflow Using Symbolic Functions And Symbolic Equationsīefore starting with any new computations, let us clean up the workspace: clear all These new features let you make the worklfow for solving ODEs and testing solutions much more smooth and convenient. In R2012a, symbolic equations and symbolic functions were introduced in the Symbolic Math Toolbox.
IS SOLVE IN THE MATLAB SYMBOLIC TOOLBOX VERIFICATION
Verification of solutions and initial conditions is not convenient, since we cannot use the subs command on string representations of ODEs.When using variables inside a string and afterwards assigning values to these variables, the values do not show up in the string.
IS SOLVE IN THE MATLAB SYMBOLIC TOOLBOX MANUAL
Manual work has been required to overcome these limitations of string syntax: But our workflow was not completely smooth. We have solved the ODE, and we have checked the correctness of the solutions. Do f(1) = 1 and f(2) = n really hold? checkInitCond1 = subs(f,t,1) Result = simplify(t^2*diff(f,2)+t*diff(f)+(t^2-n^2)*f)įinally, we should also check the initial values. But because the string input does not let us use subs to directly plug the solution into the ODE, we, again, have to do some manual work: syms t In order to verify that the solution is correct, we need to plug it into the ODE and see if this gives 0. (bessely(1, 1) - bessely(1, 2)) besselj(1, t)Īnother limitation becomes obvious when we try to check the solution. We more or less have to modify the ODE by hand replacing all appearances of n by 1: f = dsolve( 't^2*D2y+t*Dy+(t^2-1^2)*y', 'y(1)=1', 'y(2)=1', 't') Just defining n = 1Īnd re-evaluating the command f = dsolve(besselODE, 'y(1)=1', 'y(2)=n', 't') ĭoes not work, since the value for n shows up in the string defining the differential equation: besselODE Say you want to assign a special value to n, e.g., n = 1, and solve the equation again using this new value for n. Such string-based input for the dsolve function has some limitations. (n bessely(n, 1) - bessely(n, 2)) besselj(n, t)
(n besselj(n, 1) - besselj(n, 2)) bessely(n, t)īesselj(n, 1) bessely(n, 2) - besselj(n, 2) bessely(n, 1)
Here is a typical example that shows how you can solve a Bessel ODE with two given initial values: besselODE = 't^2*D2y+t*Dy+(t^2-n^2)*y' į = dsolve(besselODE, 'y(1)=1', 'y(2)=n', 't') The usual way to solve ordinary differential equations (ODEs) using the Symbolic Math Toolbox dsolve command is to set up the equations using string syntax. Solving Ordinary Differential Equations Using String Input