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에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!