function xdot=myfunc4(t,x)
xdot=zeros(2,1);
a=0.5;
xdot(1)=-a*x(1)-sin(x(2));
xdot(2)=x(1);
endfunction
x=-9:0.5:9;
v=-5:0.5:5;
dx=zeros(length(x),length(v),2);
for nx=1:length(x)
for nv=1:length(v)
dx(nx ,nv ,:)=myfunc4(0,[v(nv) x(nx)]);
end
end
clf(); champ(x, v, dx(:,:,2), dx(:,:,1))
- 常微分方程式を解こう
- という微分方程式
- 初期値、
- 計算すべきtの値は0から0.1刻みでまで
- ode()関数を使って微分方程式を解いてtの値に対応するyの値を求めて
- プロットする
function ydot=f(t, y),ydot=y^2-y*sin(t)+cos(t),endfunction
y0=0;t0=0;t=0:0.1:2*%pi;
y=ode(y0,t0,t,f)
plot(t,y)
install.packages("deSolve")
library(deSolve)
ydot<-function(t,y,pars){
list(y^2-y*sin(t)+cos(t))
}
y<-0
times<-seq(from=0,to=2*pi,by=0.1)
out1<-ode(y = y, times = times, func = ydot)
plot(out1)
par(new=TRUE)