Difficulty solving and plotting solution to complicated second order ODE.
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi all,
I am trying to solve quite an ODE that I have formed in my attempt to model the removal of a particle from a thin film. In order to solve this, I am trying to make use of the "odeToVectorField" function in order to break down the second order equation into two first order ODE's.
My script seems to work perfectly, where I can form a MATLAB function of the two first order ODE's, however this is unable to be solved when I call ODE45. I am presented with the following error messages:
Index exceeds matrix dimensions.
Error in symengine>makeFhandle/@(Y,t)[Y(2);(Y(2).*(-6.136363636363637e3))./Y(1)+9.810000000000001]
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in furthertests (line 16) sol = ode45(M,[0 20],[1 0]);
I am really not sure why this is occuring. Here is the script that I am currently running:
clc;
clear;
D0 = 0.1*10^-9;
R = 1*10^-6;
m = (4/3)*pi*(R^3)*1100;
mew = 1.5;
F0 = m*9.81;
syms y(t)
eqn = m.*diff(y,2)== F0 - 6.*pi.*mew.*(R.^2).*(1./y).*diff(y);
V = odeToVectorField(eqn)
%This breaks down the second order ODE into two separate first order ODE's
M = matlabFunction(V,'vars',{'Y','t'})
sol = ode45(M,[0 20],[1 0]);
fplot(@(t)deval(sol,t,1), [0, 20])
Apologies for the dodgy spacing in my script, I couldn't figure out how to space it properly on this forum.
Any help you could give with this would be much appreciated.
Cheers.
댓글 수: 0
채택된 답변
Star Strider
2018년 1월 14일
The time (or other independent variable) has to come first in the argument list of ODE functions.
Reverse them and it works:
M = matlabFunction(V,'vars',{'t','Y'})
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!