子绘图odes15 MATLAB

时间:2014-12-11 18:58:35

标签: matlab plot matlab-figure

我正在努力练习进行最后的决定,我遇到了一个老问题,我在使用odes15和sub plotting时遇到了麻烦。我尝试使用MATLAB主网站上给出的示例,但无法弄清楚它为什么会起作用。问题是:

enter image description here enter image description here

这是我的代码:

 function dx = problem1(t,x)

P1 = 0.028735 ;
P2 = 0.028344 ;
P3 = 5.035 * 10^(-5) ;
Vi = 12 ;
n = 5/54 ;
D(t) = 3*exp(-0.05*t) ;
U = 3 ;

dx = zeros(3,1);
dx(1) = -P1*(G-Gb) - (X-Xb)*G + D(t) ;
dx(2) = -P2*(X-Xb) + P3*(I-Ib) ;
dx(3) = -n*I + U(t)/Vi ;

[T,X] = ode15s(@problem1, [0 24], [4.5 15 15]) ;
plot(T,X(:,1),'-',T,X(:,2),'-.',T,X(:,3),'.')

1 个答案:

答案 0 :(得分:0)

您必须构成由problem1命名的M函数文件并编写以下代码。然后在命令窗口中编写下面的命令[***]。你会得到这样的输出:

enter image description here

function dx = problem1(t,x)     
    P1 = 0.028735 ;
    P2 = 0.028344 ;
    P3 = 5.035 * 10^(-5) ;
    Vi = 12 ;
    n = 5/54 ;
    D_t = 3*exp(-0.05*t) ;
    U_t = 3 ;
    Gb = 4.5;
    Xb = 15;
    Ib = 15;

    G = x(1);
    X = x(2);
    I = x(3);

    dx = zeros(3,1);
    dx(1) = -P1*(G-Gb) - (X-Xb)*G + D_t ;
    dx(2) = -P2*(X-Xb) + P3*(I-Ib) ;
    dx(3) = -n*I + U_t/Vi ;
end

[***]将以下代码写入命令窗口:

x0        = [4.5 15 15];
update    = 0.1;
t_span    = [0 update];
output    = x0;
time_axis = 0:update:24;


for k = 1 : 24 / update
    [T,X]  = ode15s(@problem1, t_span, x0) ;
    x0     = X(end, :);
    output = [output; x0];
end

figure, 

subplot(3, 1, 1)
plot(time_axis, output(:, 1), '-'); title('G')

subplot(3, 1, 2)
plot(time_axis, output(:, 2), '-.'); title('X')

subplot(3, 1, 3)
plot(time_axis, output(:, 3), '.'); title('l')