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
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
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),'.')
Accepted Answer
Mischa Kim
on 13 Mar 2014
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 Comments
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 .
NITA JAIN
on 14 Mar 2014
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
Mischa Kim
on 14 Mar 2014
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.
NITA JAIN
on 14 Mar 2014
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.......
Mischa Kim
on 14 Mar 2014
Yep. Both t and y(1) have the same initial values and increase with the same slope (= derivative) of 1.
NITA JAIN
on 14 Mar 2014
thnx.....!!!!! and how to overcome NaN in 3rd code......
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)