ode45 failing to produce a solution
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm looking for some help with ode45 solver.
I have the following set of ODEs:
function Y=f(~,X)
n=1.3;
dF1deta=X(2);
dF2deta=n^(-1)*((X(2)^(2)+X(4)^(2))^((n-1)/2))^(-1)*((X(1)^(2)-X(3)^(2)+(-X(5))*X(2))*(1+(n-1)*(X(2)^(2)+X(4)^2)^(-1)*X(4)^(2))-(n-1)*X(2)*X(4)*(X(2)^(2)+X(4)^(2))^(-1)*(2*X(1)*X(3)+(-X(5))*X(4)));
dG1deta=X(4);
dG2deta=n^(-1)*((X(2)^(2)+X(4)^(2))^((n-1)/2))^(-1)*((2*X(1)*X(3)+(-X(5))*X(4))*(1+(n-1)*(X(2)^(2)+X(4)^2)^(-1)*X(2)^(2))-(n-1)*X(2)*X(4)*(X(2)^(2)+X(4)^(2))^(-1)*(X(1)^(2)-X(3)^(2)+(-X(5))*X(2)));
dH1deta=(3*n+1)/(n+1)*X(1);
Y = [dF1deta; dF2deta; dG1deta; dG2deta; dH1deta];
I need to solve this as such:
etaspan = [0 20];
Xinit = [0; 0; 0; 0; -0.73591509];
options = odeset('AbsTol', 1e-10, 'RelTol', 1e-8);
[eta,X]=ode45(@f,etaspan,Xinit,options);
figure;
hold all;
plot(eta,X(:,1));
plot(eta,X(:,3));
plot(eta,-X(:,5));
hold off;
xlabel('\eta')
hleg = legend('F','G','-H','Location','NorthWest');
In this case ode45 fails to produce a solution. I'm guessing this is because of the four initial conditions being set to zero? Is there another solver that will be able to handle this?
Thanks.
2 Kommentare
Jan
am 21 Nov. 2012
Bearbeitet: Jan
am 21 Nov. 2012
What does "ODE45 fails" explicitly mean? Do you get an error message or do the results differ from your expectations? Please explain such important details.
An absolute tolerance of 1e-10 is really very tiny. I cannot imagine any scientific field, where an ODE45 integration with such a tiny tolerance has any kind of power and meaning.
Antworten (2)
Jan
am 21 Nov. 2012
This does not concern your problem, but I like clean code, because it makes debugging much easier.
- 1/X is much cheaper than x^-1
n = 1.3;
XX = X .^ 2;
dF2deta = 1 / (n * ((XX(2) + XX(4))^((n-1)/2)) * ...
((XX(1)-XX(3) - X(5)*X(2)) * ...
(1+(n-1) *(XX(2)+XX(4)) * XX(4)) - ...
(n-1) * X(2)*X(4) / (XX(2)+XX(4)) * ...
(2*X(1) * X(3) - X(5) * X(4))));
Without an editor for the matching of parenthesis the cleanup was not secure. So please test this, or better apply the shown simplifications by your own. Do you see the optical improvements? Usually theye are accompanied by a faster processing also. But this can still be improved.
0 Kommentare
Jan
am 21 Nov. 2012
You can use the debugger to find out, if your function replies Y value differing from 0. Simply set a breakpoint in a lines of your function "f" and look, what's going on.
Again I repeat, that in my opinion lines like these cannot be debugged by a human - at least not with a reasonable effort:
dG2deta=n^(-1)*((X(2)^(2)+X(4)^(2))^((n-1)/2))^(-1)*((2*X(1)*X(3)+(-X(5))*X(4))*(1+(n-1)*(X(2)^(2)+X(4)^2)^(-1)*X(2)^(2))-(n-1)*X(2)*X(4)*(X(2)^(2)+X(4)^(2))^(-1)*(X(1)^(2)-X(3)^(2)+(-X(5))*X(2)));
Simplify your code to simplify your life!
5 Kommentare
Jan
am 27 Nov. 2012
Ok. Now what does "fails to produce a solution" mean? Do you get an error message of a trajectory, which stays on the zero value?
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!