我正在学习python、numpy和scipy。我想知道是否有可能将matlab中的这类函数翻译成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
在这个例子中,n是数字,例如15;
t是时间阵列
AH=[15]x t矩阵
t0=0
tf=20(例如)
u_env=[20,20,20,20,20,10,20,2,20,20,020,20,30,20,20]
utop_init=20
utop_final=40;ubottom=20;
te_idx=4;
是的,这是可能的。沿着这些路线:
http://scipy-central.org/item/13/2/integrating-an-initial-value-problem-multiple-odes
只需将"vode"替换为"zvode"即可。或者:
https://stackoverflow.com/search?q=%5Bscipy%5D+复数+ode