0

したがって、初期条件 x(0)= 0 および v(0) = x'(0) = v_o = 1 で x''(t) = -x(t)^p を解く必要があります。パラメーター p の値は 1 です。

これは私が持っているものです:

function [t, velocity, x] = ode_oscilation(p)

y=[0;0;0];
    % transform system to the canonical form

    function y = oscilation_equation(x,p)
        y=zeros(2,1);
        y(1)=y(2);
        y(2)=-(x)^p;
        %  to make matlab happy we need to return a column vector
        % so we transpose (note the dot in .')
        y=y.'; 
    end

    tspan=[0, 30]; % time interval of interest

    [t,velocity,x] = ode45(@oscilation_equation, tspan, 1); 

    t = y(:,1);
    xposition=y(:,3);
    velocity=y(:,2); 

end 

これは私が受け取るエラーメッセージです:

ode_oscillation(1) odeearguments の使用エラー (91 行目) ODE_OSCILLATION/OSCILATION_EQUATION は列ベクトルを返さなければなりません。

ode45 のエラー (114 行目) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

ode_oscillation のエラー (17 行目) [t,velocity,x] = ode45(@oscilation_equation, tspan,1);

4

1 に答える 1

3

ここでいくつか問題が発生しています。まず、からhelp ode45

ode45 非スティッフな微分方程式を中次法で解きます。

[TOUT,YOUT] = ode45(ODEFUN,TSPAN,Y0) with TSPAN = [T0 TFINAL] integrates 
the system of differential equations y' = f(t,y) from time T0 to TFINAL 
with initial conditions Y0. 

ode45関数が必要であることに注意してくださいf(t,y)。ここでsize(t) == [1 1]、時間およびsize(y) == [1 N]または[N 1]解の値を表します。oscilation_equation入力引数の順序が逆になり、 time の代わりに定数パラメーターを入力しpますt

また、初期条件Y0は と同じサイズにする必要がありyます。そうsize(y0) == [N 1][1 N]。があり1、明らかにエラーが発生しています。

また、出力引数およびはからの出力引数として設定されていないため、完全に無視され、エラーになりtます。また、ほとんどの場合、それらの名前はの出力引数に対応していません。また、の列から抽出する順序が正しくありません。xpositionvelocityyode45ode_oscilationy

したがって、要約すると、すべてを次のように変更します。

function [t, v, x] = ode_oscilation(p)

    % initial values
    y0 = [0 1];           

    % time interval of interest
    tspan =[0 30]; 

    % solve system 
    [t,y] = ode45(@(t,y) [y(2); -y(1)^p], tspan, y0);

    % and return values of interest
    x = y(:,1);
    v = y(:,2);

end
于 2012-11-05T05:33:27.627 に答える