Академический Документы
Профессиональный Документы
Культура Документы
for the motion of a particle of constant mass m. In general, the force F depends upon the position x(t) of the particle at time t, and thus the unknown function x(t) appears on both sides of the differential equation, as is indicated in the notation F(x(t)). Ordinary differential equations are distinguished from partial differential equations, which involve partial derivatives of functions of several variables. Ordinary differential equations arise in many different contexts including geometry, mechanics, astronomy and population modelling. Many famous mathematicians have studied differential equations and contributed to the field, including Newton, Leibniz, the Bernoulli family, Riccati, Clairaut, d'Alembert and Euler. Much study has been devoted to the solution of ordinary differential equations. In the case where the equation is linear, it can be solved by analytical methods. Unfortunately, most of the interesting differential equations are non-linear and, with a few exceptions, cannot be solved exactly. Approximate solutions are arrived at using computer approximations
ode23, ode45, ode113, ode15s, ode23s, ode23t, ode23tb initial value problems for ordinary differential equations Syntax
Solve
odefun
A function handle that evaluates the right side of the differential equations. All solvers solve systems of equations in the form or problems that involve a mass matrix,
. The ode23s solver can solve only equations with constant mass matrices. ode15s and ode23t can solve problems with a mass matrix that is singular, i.e., differential-algebraic equations (DAEs).
tspan
A vector specifying the interval of integration, [t0,tf]. The solver imposes the initial conditions at tspan(1), and integrates from
decreasing. Specifying tspan with more than two elements does not affect the internal time steps that the solver uses to traverse the interval from
y0
T Y
Column vector of time points. Solution array. Each row in Y corresponds to the solution at a time returned in the corresponding row of T.
TE YE IE
The time at which an event occurs. The solution at the time of the event. The index i of the event function that vanishes.
Example 7.1 Obtain the numerical solution of the following first order differential equation: dx/dt = -2x as x(0) =1 , for 0 < t < 10 , using ode45 solver Solution An M file containing MATLAB command is written in edit window function xdot = func1(t,x) xdot= -2.*x save this function as M-file named as func1.m and use the following command in the command window: tspan = [0,10]; yo=1; [t,x]=ode45('func1',tspan,yo); plot(t,x); grid on xlabel('time t') ylabel('x') title('graph between solutions obtained and time')
graph between solutions obtained and time 1 0.9 0.8 0.7 0.6 x 0.5 0.4 0.3 0.2 0.1 0
5 time t
10
The symbolic toolbox is a bit difficult to use but it is of great utility in applications in which symbolic expressions are necessary for reasons of accuracy in calculations. The toolbox simply calls the MAPLE kernel with whatever symbolic expressions you have declared, and then returns a (usually symbolic) expression back to MATLAB. It is important to remember that MAPLE is not a numeric engine, which means that there are certain things it doesn't let you do that MATLAB can do. Rather, it is useful as a supplement to provide functions which MATLAB, as a numerical engine, has difficulty with. The symbolic math toolbox takes some time to initialize, so if nothing happens for a few seconds after you declare your first symbolic variable of the session, it doesn't mean you did anything wrong. The MATLAB student version comes with a copy of the symbolic math toolbox. Symbolic Variables You can declare a single symbolic variable using the 'sym' function as follows. >> a = sym('a1') a = a1 You can create arrays of symbolic expressions like everything else >> a2 = sym('a2'); >> a = [a1, a2] a = [ a1, a2]
Symbolic variables can also be declared many at a time using the 'syms' function. By default, the symbolic variables created have the same names as the arguments of the 'syms' function. The following creates three symbolic variables, a b and c >> syms a b c >> a
a=a
Symbolic Numbers Symbolic numbers allow exact representations of fractions, intended to help avoid rounding errors and representation errors. This section helps explain how to declare them. If you try to add a number into a symbolic array it will automatically turn it into a symbolic number >> syms a1, a2; >> a = [a1, a2]; >> a(3) = 1; %would normally be class 'double' >> class(a(3)) ans = sym Symbolic numbers can also be declared using the syntax a(3) = sym('number'). The difference between symbolic numbers and normal MATLAB numbers is that, if possible, MAPLE will keep the symbolic number as a fraction, which is an exact representation of the answer. For example, to represent the number 0.5 as a fraction, you can use Other class conversions are possible as well; for instance, to change it into a string use the 'char' function. There is no function to directly change a symbolic variable into a function handle, unfortunately. A caveat: Making a symbolic variable of negative exponentials can create problems if you don't use the correct syntax. You cannot do this >> sym('2^-5') ??? Error using ==> sym.sym>char2sym Not a valid symbolic expression.
Differentiation and Integration with One Variable Differentiation of functions with one or more variables is achieved using the 'diff' function. As usual, you can either define the function before the differentiation (recommended for M files) or you can manually write it in as an argument (recommended for command-line work). If there is only one symbolic variable in the expression, MATLAB assumes that is the variable you are differentiating with respect to. The syntax is simply: >> syms x >> f = x^2 - 3*x + 4; >> diff(f) % or diff('x^2 - 3*x + 4') ans = 2*x - 3
Integration, similarly, is achieved using the 'int' function. Only specifying the function results in an indefinite integral, or the antiderivative of the function. >> int(f) ans = x^3/3 - (3*x^2)/2 + 4*x
Note that if you only specify one output argument (or none at all), the 'int' function omits the integration constant. You just have to know it's there. To do a definite integral on a one-variable function, simply specify the beginning and end points. >> int(f, 0,1) ans = 17/6
EXAMPLE 8.2
Evaluate: 1. a=9/5 2. b=6/5+4/3 using symbolic computation solution: >> a=sym(9)/sym(5)
EXAMPLE 8.4
suppose , a=x^n. diffenciate a w.r.t x the commands used are as syms x n; a=x^n; diff(a) result obtained is given below ans =
x^n*n/x
EXAMPLE 8.5
Find the integration of the following 1. a=cos(x)_ 2. a=x2 solution 1.sym x; a=cos(x); int(a) ans = sin(x) 2.syms x a= x^2; int(a) ans = 1/3*x^3