ODE - 2.24

197 days ago by PatrickHammer

%hide %latex $x'(t)=x(t) $\newline $\frac{dx(t)}{dt}=x(t) $\newline $t+c_1=\int\frac{dx(t)}{x(t)} $\newline $x(t):=y$ $\newline $t+c_1$=\int\frac{dy}{y}=log(y)+c_2=log(x(t))+c_2 $\newline $=> x(t)=e^{c_1-c_2+t} $ \newline mit $c:=e^{c_1-c_2}$: \newline $x(t)=c*e^t$ \newline Soll $x(0)=1$ gelten folgt aus $e^0=1$ dass $c=1$ sein muss. 
       
var('c t') #Definitionen c=1 #siehe oben f(t)=c*e^t #unser Lösungsschema h=10^(-1) #Schrittgröße t(m)=0+m*h #bei t=0 starten #Euler-Verfahren: f_h=lambda m: f_h(m-1)+f(t(m-1))*h if m>0 else 1 #Runge-Kutta-verfahren: k1(m)=f(t(m)) k2(m)=f(t(m)+h/2) k3(m)=k2(m) k4(m)=f(t(m+1)) r_h=lambda m: r_h(m-1)+h/6*(k1(m-1)+2*k2(m-1)+2*k3(m-1)+k4(m-1)) if m>0 else 1 #lasset uns plotten start=0; to=2 plot(lambda x: f_h(x/h),(x,start,to),color="blue")+plot(f,(x,start,to),color="red")+plot(lambda x: r_h(x/h),(x,start,to),color="green") 
       
Sieg für Runge und Kutta. Euler fliegt schon zuvor aus der Kurve, ich hoffe er nimmts gelassen.