MATLAB: Using ODE Solvers?

This is really a basic question, but this is the first time I've used MATLAB and I'm stuck. I need to simulate a simple series of RC networks using 3 different digital processing techniques. I think I understand how to use the ode solvers, but I have no idea how to enter the differential equation of the system. Do I need to do this through an m file?

It's just a simple RC circuit of the form:

RC dy(t)/dt + y(t) = u(t)

      

with zero initial conditions. I have values ​​for R, C step length and simulation time, but I don't know how to use MATLAB especially well.

Any help is greatly appreciated!

+1


source to share


2 answers


You will need a function file that takes t and y as input and gives dy as output. It will be its own file with the following header.

function dy = rigid(t,y)

      

Save it as rigid.m in the MATLAB path.

From there, you put your differential equation. You now have a function. Here's a simple one:

function dy = rigid(t,y)

dy = sin(t);

      

In command line or script, you need to execute this function with ODE45

[T,Y] = ode45(@rigid,[0 2*pi],[0]);

      



This will give you your function (rigid.m) from time 0 to time 2 * pi with an initial y of zero .

Plan this:

plot(T,Y)

      

alt text

More MATLAB documentation can be found here:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ode23tb.html

+4


source


The Crash Matlab Official Course (PDF Warning) has a section on the ODE solution, as well as many other resources that I found helpful when running Matlab.



+1


source







All Articles