# MATLAB study notes the seventh chapter--Numerical solution of ordinary differential equation (ODE)

Source: Internet
Author: User

1. We solve ode by calling the ODE32 function:

[T,y] = Ode23 (' Func_name ', [Start_time, End_time], y (0))

The ODE45 function uses a higher-order Runge-kutta formula.

First we define the function, we create a. m file, and enter the following content.

function Ydot = eq1 (t,y)
Ydot = cos (t);

The statements that are called are:

>> [T,y] = Ode23 (' eq1 ', [0 2*pi],2);

>> f = 2 + sin (t);

>> plot (t,y, ' o ', t,f), Xlabel (' t '), Ylabel (' Y (t) '), axis ([0 2*PI 0 4])

>> err = zeros (size (y));

Now we use the For loop to iterate through the data to calculate the relative error at each point:

>> for i = 1:1:size (y)
Err (i) = ABS ((f (i)-y (i))/F (i));
End

MATLAB study notes the seventh chapter--Numerical solution of ordinary differential equation (ODE)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.