How do I solve and plot a system of differential equations?
32 views (last 30 days)
I'm new with MATLAB so, even if i usually try to solve my problems by my own, this time the problem is far over my ability.
I need to find a way to solve the following differential equations' system:
Mb'' + Kb = P
b(0) = h
M and K are two matrix n x n known
b is a vector of n line time-depending
P is a n x 1 vector known
My professor suggested me to turn the system, without going into details, into this one:
y' + Ay = G
y is a 2n x 1 vector
A is a 2n x 2n known matrix
G is a 2n x 1 known vector
I would like to calculate the value of Yi in different times (such as time 0 , 1, ... ,10), having so a matrix with the value of each y at a given time in each column and the value of a single Yi in each row (or viceversa, ofc)
Moreover I only need the first half of the vector Y (the first n terms) and I can discard the other terms.
Since I'm here i also ask you how to plot this in a 3D plot, or a 2D plot+color.
Andrew Newell on 28 Jan 2011
To solve the differential equation, you could use ode45 or one of the other differential equation solvers (if you type "doc ode45" you'll see a list of them). An example call:
[T,Y] = ode45(odefun,tspan,y0);
For odefun you could use the inline definition:
odefun(y) = @(y) -A*y + G;
If you want the solution at specific times, you'll need to give the times in tspan.
To plot, if n=1 in your problem,