Octave 用ode45解八度常微分方程
我试图用八度音阶,特别是函数ode45来解下面的ODEOctave 用ode45解八度常微分方程,octave,numerical-methods,Octave,Numerical Methods,我试图用八度音阶,特别是函数ode45来解下面的ODE dx/dt=x(1-x/2),0ode45期望ODE函数的参数顺序为(时间、状态),因此正好相反。您有效地集成了t-t^2/2,得到的函数0.5+t^2/2-t^3/6就是您在绘图中得到的函数。谢谢!我发现了错误。我应该写f(t,x),而不是f(x,t) clear all close all % Differential Equation: x' = x(1-x/2) function dx = f(x,t) dx = x*(1-x
dx/dt=x(1-x/2),0
ode45
期望ODE函数的参数顺序为(时间、状态)
,因此正好相反。您有效地集成了t-t^2/2
,得到的函数0.5+t^2/2-t^3/6
就是您在绘图中得到的函数。谢谢!我发现了错误。我应该写f(t,x),而不是f(x,t)
clear all
close all
% Differential Equation: x' = x(1-x/2)
function dx = f(x,t)
dx = x*(1-x./2);
endfunction
% Exacte Solution: 2*e^t/(3+e^t)
function xexac =solexac(t)
xexac = (2*exp(t))./(3+exp(t));
endfunction
x0=0.5; %%Initial condition
T=10; %% maximum time T
t=[0:0.1:T]; %% we choose the times t(k) where is calculated 'y'
sol=ode45(@f,[0,T],x0); %% numerical solution of (E)
tt=sol.x;y=sol.y; %% extraction of the results
clf;hold on ; %% plot the exact and numerical solutionss
plot(tt,y,'xr')
plot(t,solexac(t),'-b')
xlabel('t')
ylabel('x(t)')
title('Chemostat Model')
legend("Numerical Solution","Exacte Solution ")