I am trying to plot this function dxdt=N0*si​n(omega*t)​*x*(1-x/K) to get a 3-D plot but my code does not work,where is the error?

3 次查看(过去 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.

采纳的回答

Roger Stafford
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
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.
Avan Al-Saffar
Avan Al-Saffar 2014-8-8
Thanks a lot for your explanation but actually the problem that I am asking for it is related to the meshgrid, there is something not define well at the beginning but I do not how to deal with it.
Regards

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by