while running this code i am unable to get y (1) ,y(2) and y(3)values.y(1) is coming similar to value of indepent variable and y(2),y(3) is coming 1 &0 resp.Plz. guide where am i getting wrong. thnx
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
function dydt = ode5(t,y) dydt = zeros(3,1); % a column vector dydt(1) = y(2); dydt(2) = y(3); dydt(3) = (-3.06091)*((y(2)^2)+(y(1)*y(3)))*(y(3)^0.67); end
options = odeset('RelTol',1e-6,'AbsTol',[1e-6 2e-6 3e-6]); [t,y] = ode45(@ode5,[0 10],[0 1 0],options); plot(t,y(:,1),'-',t,y(:,2),'-.',t,y(:,3),'.')
채택된 답변
Nita, your code is good, the output from MATLAB is correct.
Looking at your DE
dydt(1) = y(2);
dydt(2) = y(3);
dydt(3) = (-3.06091)*((y(2)^2)+(y(1)*y(3)))*(y(3)^0.67);
the derivatives at t = 0 are
dydt(1) = 1
dydt(2) = 0
dydt(3) = 0
which means that y(1) is increasing, y(2) and y(3) remain constant, y(2) = 1, y(3) = 0. At the next time step, t = dt, you get the same derivatives, which you therefore get for all t. As a result, y(1) is increasing linearly with a slope of 1, whereas y(2) and y(3) remain constant. You will get a different result for different intial conditions.
댓글 수: 8
Thnx Mischa for your quick answer . i would like to slove this nonlinear diff. equa. with same initial conditions. so what i am getting as answer is correct? i am new to matlab so wanted to confirm whether the developed code is corret or not .
Hi Mischa , if what you explained in the above code is correct then how i am getting different values for y(2) an y(3) in the following code :
function dy = ode4(t,y) dy = zeros(3,1); % a column vector dy(1) = y(2); dy(2) = y(3); dy(3) = (y(1)*y(3)+(y(2)^2))*(-0.3333); end options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]); [t,y] = ode45(@ode4,[0:1.25:50],[0 1 0],options) plot(t,y(:,1),'-',t,y(:,2),'-.',t,y(:,3),'.')
plz. guide.
Nita, to your first question. Yes, it is correct. Use
[t,y] = ode45(@mine,[0 10],[0 0.01 0.01],options);
for example, to see a different result for different initial conditions. To your second question: you get different values because your system of DE is different.
Hello Mischa, thnx for your reply. but if you see 2nd system is similar to 1st one only. only difference in 1st one is y(3) has additional factor y(3)^0.67. it means small chnage in system creat this difference in solution.plz answer. actualy i am sovling system of DE for different values of n and in case of n=1 ans is coming correct. For n<1 and n>1 code is executed but in n<1 case answer is as per ist code and in n>1 case plot is coming blank and array is showing NaN. how to overcome this problem.for your reference n>1 case code is like :
function dz = ode6(t,z) dz = zeros(3,1); % a column vector dz(1) = z(2); dz(2) = z(3); dz(3) =(-0.1481)*[z(2)^2+(z(1)*z(3))]*[z(3)^(-0.5)]; end
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]); [t,z] = ode45(@ode6,[0:0.25:25],[0 1 0],options); plot(t,z(:,1),'-',t,z(:,2),'-.',t,z(:,3),'.') plz. guide
Trust me, you are good. The change in dydt(3) changes y(3), which in turn affects dydt(2) = y(3), which changes y(2) and therefore y(1). It's a so-called coupled system of DE.
fine .....what you are saying i am agreeing to that .coud you elaborate when i run ist code why t and y(1) values are coming exactly numerically same.......
Yep. Both t and y(1) have the same initial values and increase with the same slope (= derivative) of 1.
thnx.....!!!!! and how to overcome NaN in 3rd code......
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
