marco
marco

Reputation: 975

Matlab -> scipy ode (complex) function translation

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;

Upvotes: 0

Views: 505

Answers (1)

pv.
pv.

Reputation: 35145

Yes, it's possible. Along these lines:

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

Just replace 'vode' with 'zvode'. Or:

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

Upvotes: 1

Related Questions