Problem in solving highly complex second order ODE
Show older comments
Hi all,
I have formed a model for the removal of a small particle from a fluid interface, which has resulted in a rather complex second order ODE. I am trying to solve this by using "odeToVectorField" to break down the ODE into two first order equations. However, when I am running my script I am finding that it is taking a very long time to produce any result...or even error message. When it does, this is the error message I see:
Error using deval (line 132)
Attempting to evaluate the solution outside the interval [0.000000e+00, 8.145653e-08] where it is defined.
Error in @(x)deval(sol,x,1)
Error in fplot (line 104)
x = xmin+minstep; y(2,:) = feval(fun,x,args{4:end});
Error in SolutionAltered (line 36)
fplot(@(x)deval(sol,x,1), [0,100]).
For some reason I am having trouble typing my script into the text box, so a picture will have to suffice. (Sorry about how messy it is).


Now, having read around it seems as though this may be due to the fact that the equation is discontinuous in nature and so the solver cannot produce a solution. I have also attempted to use ODE23s as I suspect the problem is one in which is highly stiff, however this has not worked either. In all honesty my understanding of this is a bit clouded, so I was just looking for a second opinion as to what may be wrong, and how it is you recommend that I could get around this.
Any help would be great, Cheers!
1 Comment
Jan
on 14 Jan 2018
Please post the code as text. It is easy, see http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099. Posting the code as screenshots on a different server is rather inconvenient for the readers. You can insert code in the question, attach it as file, and if you really need a screenshot images can be posted also.
Answers (1)
Star Strider
on 14 Jan 2018
If you are integrating the same equation you posted earlier, deval and fplot will just complicate your code.
Do this instead:
sol = ode45(M,[0 100],[1 0]);
figure
plot(sol.x, sol.y(1,:))
Also, if you have a ‘stiff’ system, ode15s may be a better choice.
13 Comments
Peter
on 14 Jan 2018
Star Strider
on 14 Jan 2018
Posting your ODE would help. I can’t help with it if I don’t have it.
Peter
on 14 Jan 2018
Peter
on 14 Jan 2018
@Peter: Screenhots are useless for us. We cannot run them, we cannot search them, we cannot edit them. If you want help then simply upload your code by clicking the paperclip button.
And if you really do need screenshots there there is no reason why you need to use any third-party website. I uploaded the two images in your question simply by clicking on the image button: notice how they are displayed correctly.
Code can be included as text (e.g. copy-and-paste or by typing it in), then simply select the code and click the {} Code button to format it correctly as code.
You can read more about how to use this forum by reading the help:
Peter
on 14 Jan 2018
Peter
on 14 Jan 2018
Peter
on 14 Jan 2018
Star Strider
on 14 Jan 2018
@Peter — I retrieved the missing constants and am attempting to run your code. It’s been running for 15 minutes on my laptop, showing no warnings. I’ll wait a few minutes and go do something else.
The code I’m running:
D0 = 1E-9;
R = 1E-6;
T = 1.5E-4;
CA = 135;
CAR = CA.*(pi/180); %Contact Angle in Radians
Zc = R.*(1+cos(CAR)); %Capillary Ribse
rohp = 1100; %Particle Density
roha = 1.2;
roho = 900;
g = 9.81;
m = (4/3)*pi*(R.^3)*rohp; %Particle Mass
mew = 0.055;%Oil Viscosity
F0 = m*9.81; %Particle Weight
surf = 32*10^-3; %surface tension between oil and air
M = @(t,Y)[Y(2);(Y(2).*(-2.25e2))./Y(1)+sin(pi.*(3.0./4.0)+acos(Y(1).*1.0e6-1.492928932188135e2)).*sqrt(-(Y(1).*1.0e6-1.492928932188135e2).^2+1.0).*4.363636363636364e7+9.810000000000001];
sol = ode15s(M,[0 100],[D0 0]);
figure
plot(sol.x, sol.y(1,:))
Peter
on 14 Jan 2018
Star Strider
on 14 Jan 2018
Edited: Star Strider
on 14 Jan 2018
My pleasure.
I finally had to reboot my laptop to stop the integration, after waiting nearly an hour. I believe your code is creating a singularity somewhere, the reason it’s not integrating.
I have no idea what to suggest, especially since I’m not familiar with what you’re doing.
--------------------------------------------
EDIT —
I ran this on my desktop since I didn’t want to dedicate my laptop to it.
One problem is that your ODE is producing complex results, and that may be the reason it’s taking forever and not integrating. This code (with the added odeset call, and restricting the output to be only real) integrates quickly and then encounters a singularity:
D0 = 1E-9;
R = 1E-6;
T = 1.5E-4;
CA = 135;
CAR = CA.*(pi/180); %Contact Angle in Radians
Zc = R.*(1+cos(CAR)); %Capillary Ribse
rohp = 1100; %Particle Density
roha = 1.2;
roho = 900;
g = 9.81;
m = (4/3)*pi*(R.^3)*rohp; %Particle Mass
mew = 0.055;%Oil Viscosity
F0 = m*9.81; %Particle Weight
surf = 32E-3; %surface tension between oil and air
M = @(t,Y) real([Y(2);(Y(2).*(-2.25e2))./Y(1)+sin(pi.*(3.0./4.0)+acos(Y(1).*1.0e6-1.492928932188135e2)).*sqrt(-(Y(1).*1.0e6-1.492928932188135e2).^2+1.0).*4.363636363636364e7+9.810000000000001]);
opts = odeset('OutputFcn',@odeplot);
tic
sol = ode15s(M,[0 100],[D0 0], opts);
toc
figure
semilogy(sol.x, sol.y)
This will give you a bit more information on your ODE.
Peter
on 14 Jan 2018
Star Strider
on 14 Jan 2018
My pleasure.
I certainly agree. The argument to acos is ((Y(1).*1.0e6-1.492928932188135e2), guaranteed to exceed ±1 for Y(1) >= 1.000149315184915e-06. I’m not certain how best to constrain ‘Y(1)’, although defining the acos argument to be tanh(Y(1))*1E-6 could work. That will bound it, and still be a differentiable function, so as opposed to being a ‘hard limit’, would not cause abrupt discontinuities of the sort that causes problems for the numeric ODE solvers. (I did not experiment with this. I leave that for you.)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!