Numerical solutions to differential equations The main application of MATLAB in EN40 is to analyze motion of an engineering system. To do this, you always need to solve a differential equation. MATLAB has powerful numerical methods to solve differential equations. They are best illustrated by means of examples.
Notice the two different uses of =. The ‘eq1=’ creates a MATLAB object called eq1 that stores the first equation. The object can be used in future calculations. If you want to create an equality inside an equation you have to use = = Now try (just edit your script; you don’t have to type it all in again)
This is the way we normally use MATLAB – you can solve most problems by just modifying the code below. As an example, let’s solve the Bernoulli differential equation with initial condition y = − 2 at time t=0. Here’s an ‘m’ file to do this initial_y = -2; time_range = [0,20];
For this sort of programming we use a matlab ‘M-file.’ To create an M-file, simply press the ‘New Script’ button on the main MATLAB window. (Don’t worry about what the commands actually do for now – we will discuss them in more detail soon). You can make MATLAB execute these statements by: