How do I solve and plot a system of differential equations?
9 次查看(过去 30 天)
显示 更早的评论
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
where:
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
where:
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.
0 个评论
回答(1 个)
Andrew Newell
2011-1-28
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,
plot3(T,Y(1),Y(2))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!