你如何在MATLAB中使用numjac函数?

时间:2018-03-28 00:17:03

标签: matlab math ode differential-equations

此特定功能的documentation online很差,我正在寻找一个如何使用它的示例。它似乎需要9个以上的论点,但我不完全确定它们是什么。我正在使用梯形规则来实现函数,但是,我缺少计算关于y和t的偏导数的函数。我相信在MATLAB中为t计算一个是另一种情况,但在这里,我只是想用MATLAB来计算y。

我最初使用以下输入:

func = @(t,y)(y.^2+y+t);
interval = [0 1];
y0 = 0;

[steps, derivY, derivJ, W, inverseW] = getTrapezoidalODEValues(func, interval, y0)

我设置了这样的功能:

function [h,J,T,W,iW] = getTrapezoidalODEValues(odefun,tspan,y0,options)
    if (nargin==3)
        options = odeset();
    end

    h = NaN; J(0) = NaN; T(0) = NaN; W(0) = NaN; iW = NaN;

    [t,yy] = ode(odefun,tspan,y0,options);
    [nstep,ndim] = size(yy);

    d = 1/(2+sqrt(2));

    for j=2:nsteps
        h = t(j)-t(j-1);
        I = eye(???,???); % identity matrix
        quadpoly = ???; % the quadratic polynomial
        J(j-1) = numjac(???); % <--partial derivative of odefun with respect to y
        T(j-1) = ???; % partial derivative of odefun with respect to t
        W(j-1) = I - h .* d .* J;
        iW(j-1) = inv(W(j-1));
    end
end

0 个答案:

没有答案