I am trying to plot this function dxdt=N0*sin(omega*t)*x*(1-x/K) to get a 3-D plot but my code does not work,where is the error?
1 次查看(过去 30 天)
显示 更早的评论
function RunOsciliationsky3D
N0all= 1:1:10;
N=length(N0all);
omegaall= 1:1:10;
M=length(omegaall);
Pmax=zeros(1,N);
Pmean=zeros(1,N);
Pall=[Pmax(i),Pmean(j)];
x=length(Pall);
for i=1:N
for j =1:N
[t,x]=ode45(@osciliation,[0 100],0.1,[],N0all(i),10,omegaall(j));
Pall(i,j)=x;
end
end
[N0x,omegay]=meshgrid(N0all,omegaall);
h=mesh(N0x,omegay,Pall);
1;
Note: x axis = Noall
y axis =omegaall
z axis = Pall, which is a matrix containing the maximum and mean values of x.
0 个评论
采纳的回答
Roger Stafford
2014-8-2
It is not necessary to call on 'ode45' to solve this particular differential equation. By ordinary methods of calculus, integration of both sides of
dx/(x*(1-x/K)) = N0*sin(omega*t)*dt
will give you
x/(K-x) = C*exp(-N0/omega*cos(omega*t))
where C is a constant whose value depends on the given initial condition. All you have to do then is put in those initial conditions for x and t to solve for C, and then solve the equation for x to obtain x as an explicit function of t involving the parameters N0 and omega. With this explicit formula you should be able to do whatever plotting you have in mind.
3 个评论
Roger Stafford
2014-8-7
I will assume you have followed my reasoning via calculus to the equation
x/(K-x) = C*exp(-N0/omega*cos(omega*t))
where C is a constant parameter whose value depends on the particular initial conditions you have with x. According to your ode45 call, the value of x is to be 0.1 when t = 0. If so, that suffices to determine what C must be:
0.1/(K-0.1) = C*exp(-N0/omega*cos(omega*0))
= C*exp(-N0/omega)
Therefore
C = 0.1/(K-0.1)*exp(N0/omega)
which gives the equation
x/(K-x) = 0.1/(K-0.1)*exp(N0/omega*(1-cos(omega*t)))
Solving this for x gives:
x = 0.1*K*exp(N0/omega*(1-cos(omega*t))) / ...
(K-0.1*(1-exp(N0/omega*(1-cos(omega*t)))))
= 0.1*K/((K-0.1)*exp(-N0/omega*(1-cos(omega*t)))+0.1)
This last equation is your explicit formula for x as a function of t, derived entirely without the use of ode45. You can do your plotting directly from this formula.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!