0

I'm learning python, numpy and scipy. I'm wonder if it is possible translate this kind of functions in matlab to python:

function [tT, u ] = SSolve5TH(n, t, t0,tf,u_env,utop_init, utop_final,ubottom,te_idx)
options = [];
[tT,u] = ode23s(@SS,t,u_env,options,@B);

function y = B(x)
    y = zeros(n,1);
    if x >= t(te_idx)

        y(1,1) = utop_final;
        y(n,1) = ubottom ;

    else

        y(1,1) = (x - t0) / ( tf - t0) * (utop_final - utop_init) + utop_init;
        y(n,1) =  ubottom ;
    end
end

function rp = SS(t,r,B)

    global AH
    rp = AH * r + B(t);

  end
end

In this example, n is number, e.g 15;

t is the time array

AH = [15]x t matrix

t0 = 0

tf = 20 (e.g)

u_env = [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20]

utop_init = 20

utop_final = 40; ubottom = 20;

te_idx = 4;

4

1 回答 1

1

是的,这是可能的。沿着这些思路:

http://scipy-central.org/item/13/2/integrating-an-initial-value-problem-multiple-odes

只需将“vode”替换为“zvode”即可。或者:

https://stackoverflow.com/search?q=%5Bscipy%5D+complex+ode

于 2012-03-16T09:57:28.970 回答