필터 지우기
필터 지우기

Numerically solve a (nonlinear) system of 64 differential equations

조회 수: 1 (최근 30일)
holistic
holistic 2016년 11월 18일
댓글: holistic 2016년 11월 20일
Hi all,
I'm trying to numerically solve a system of 64 equations with Matlab2014a and ode45 (see picture below for the equation, where Erf is the error function and Q is 64 by 64 matrix). But typing every single equation seems very tedious. So I was wondering (more like hoping) if there is some way to implement this formula in matlab without explicitly typing all the equations (and sum terms asf) i.e. using the notion below somehow with ode45?

채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 18일
N = 64;
X = sym(zeros(1, N));
lhs = sym(zeros(1,N));
rhs = sym(zeros(1,N));
for i = 1 : N
X(i) = symfun( sprintf('x%d(t)', i), t );
lhs(i) = diff(X(i), t);
end
for i = 1 : N
rhs(i) = erf(sum( (Q(i,:) .* X) .* (1 + mu * X(i)) ) - lambda*X(i));
end
Now you can go for
dsolve(lhs == rhs)
However, dsolve() is not able to solve the system symbolically. dsolve() is also not going to be able to solve the system numerically unless you also create boundary conditions.
You could proceed to
syms y
odefun = matlabFunction( rhs(:), 'vars', {t y});
and then odefun would be a function handle returning a column vector of differential values.
However... each of your xi and xj is not a variable but is instead a function xi(t) xj(t), so the odefun that was generated in this way would contain calls to functions x1, x2, x3, .... x64 . And that is a problem because you do not know what the functions are.
Perhaps, then:
N = 64;
X = sym('x', [1, N]);
rhs = sym(zeros(1,N));
for i = 1 : N
rhs(i) = erf(sum( (Q(i,:) .* X) .* (1 + mu * X(i)) ) - lambda*X(i));
end
odefun = matlabFunction( rhs(:), 'vars', {t X});
and then you could pass odefun as the first parameter to ode45
  댓글 수: 7
Walter Roberson
Walter Roberson 2016년 11월 20일
It might have been the random Q that I choose for testing purposes. All of the results were above 250 before the erf(), and erf() of that is 1 to within working position...
Yes, a different (much smaller) Q made a notable difference.
holistic
holistic 2016년 11월 20일
Thank you once again Walter!
This works now. With regard to the initial conditions in my case, I just choose some arbitrary ones. But normally, the initial conditions won't be the same for all "units".

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by