I need some manipulation with ODE45. Please help me!
이전 댓글 표시
I just wondering that why this code working wrong. Please help me! I can't manipulate the ODE function.
options=odeset('RelTol',10^-4);
[T,Y]=ode23('turshilt23',[0 300],[0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5],options);
plot(T,Y);
function dy=turshilt23(t,y,flag)
%here is some code
if(k==0)
y(1)=y(1)/2;
end
dy(1)=mu*y(1)*(1-(y(1)/m_max));
%here is some code
end
답변 (3개)
Arnaud Miege
2011년 8월 3일
2 개 추천
Also, it seems that in your function turshilt23, you haven't defined what k, mu or m_max are. Finally you compute dy(1), but you call the ode solver with an initial condition vector of length 9. You need to compute dy(2), dy(3), ... dy(9) in your function as well.
Have a look at the documentation for the ode solvers, there are various examples you can inspire yourself from.
HTH,
Arnaud
Tsogerdene
2011년 8월 3일
댓글 수: 2
Arnaud Miege
2011년 8월 3일
It works for me. What error message do you get?
Some comments:
* Your function is a function of t, y and flag but t and flag are not used. Consider replacing those with ~
* Your function defines k and y_1 as global variables, but those aren't used in the function. You can remove those two lines.
The only changes I made were therefore:
function dy=turshilt23(~,y,~)
global Global_CycB1;
global Global_CycB2;
% global k;
% global y_1;
I used 0.1 for the other two global variables Global_CycB1 and Global_CycB2. The solver solved OK.
Walter Roberson
2011년 8월 3일
Note: Using ~ in that way is not available in 2008 and earlier.
Tsogerdene
2011년 8월 8일
0 개 추천
댓글 수: 3
Walter Roberson
2011년 8월 8일
When you modify y(1) in your code, you are only modifying the _local_ y(1) . It is not possible to permanently change the y for figure iterations.
Tsogerdene
2011년 8월 8일
Walter Roberson
2011년 8월 8일
Typo correction: I meant for "future iterations"
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!