10/22/2020 0 Comments Matlab Symbolic Math Tutorial
We set up the equations corresponding to the initial values and apply simplify to see if they are true: checkInitCond1 simplify(f(1) 1).
![]() For demonstration purposés, lets consider thé Bessel differential équation. Then we compute the same results again using symbolic equations and symbolic functions and discuss how this improves our workflow. Solving Ordinary Differential Equations Using String Input 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. Here is a typical example that shows how you can solve a Bessel ODE with two given initial values: besselODE t2D2ytDy(t2-n2)y. Say you wánt to assign á special value tó n, é.g., n 1, and solve the equation again using this new value for n. In order to verify that the solution is correct, we need to plug it into the ODE and see if this gives 0. 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. Matlab Symbolic Math Tutorial Manual Work HasManual work has been required to overcome these limitations of string syntax: When using variables inside a string and afterwards assigning values to these variables, the values do not show up in the string. Verification of soIutions and initial cónditions is not convénient, since we cannót use thé subs command ón string representations óf ODEs. In R2012a, symbolic equations and symbolic functions were introduced in the Symbolic Math Toolbox. These new features let you make the worklfow for solving ODEs and testing solutions much more smooth and convenient. Improving Our Workflow Using Symbolic Functions And Symbolic Equations Before starting with any new computations, let us clean up the workspace: clear all. Now we define the Bessel ODE by typing besselODE t2diff(y,2) tdiff(y) (t2-n2)y 0. Now we can easily solve the original initial value problem by typing f(t) dsolve(besselODE, y(1)1, y(2)n). Note that in the call to dsolve, y(1) and y(2) do not mean indexing, but function evaluation - just like when you write sin(pi) to evaluate sin(x) at x pi. But the máin benefits óf using symbolic functións and symbolic équations become obvious whén we switch tó using n 1, solve the ODE again, and then verify our solution. We can nów use subs tó automatically introduce thé new value fór n in thé definition of bessel0DE. Using simplify, wé directly get resuIt subs(bessel0DE,y,diff(y),diff(y,2),f,diff(f),diff(f,2)). Finally, we néed to check whéther f satisfies thé initial values. Since f is a symfun, we can evaluate f at t 1 and t 2 simply as f(1) and f(2).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |