필터 지우기
필터 지우기

Solving non homogenous differential equations numerically using ode45 etc

조회 수: 9 (최근 30일)
How is a non homogenous differential equation solved in MATLAB using ode45 or ode23. I have a function like:- dmdt = a*exp(Asin(wt) + (2-m)^2);
Can I obtain the numerical solution for this?
Thanks in advance

채택된 답변

Mischa Kim
Mischa Kim 2014년 10월 29일
편집: Mischa Kim 2014년 11월 4일
Sarah, yes you can. The typical approach for such an example is to create two functions:
function my_EOM()
a = 1;
A = 1;
w = 1;
fun = @(w,x) sin(w.*x);
param = {a; A; w; fun};
IC = -1;
[t,m] = ode45(@EOM,[0 1],IC,[],param);
plot(t,m)
xlabel('t')
ylabel('m')
grid
end
function dmdt = EOM(t, m, param)
a = param{1};
A = param{2};
w = param{3};
fun = param{4};
dmdt = a*exp(A*fun(w,t) + (2 - m)^2);
end
Save both functions in the same .m-file and with name my_EOM.m. Execute and enjoy.
  댓글 수: 2
Sarah Ghosh
Sarah Ghosh 2014년 11월 4일
Thanks for your answer, but is there no possible way to pass the external input to the ode function (here, EOM). I basically want to plot and check the external input and the solution obtained via the differential equation. So, I need the external input in the my_EOM function so that I have both these two as vectors. Is there any way to do that? Or do I just create the input again in my_EOM?

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

추가 답변 (1개)

Orion
Orion 2014년 10월 29일
you can rewrite your equation as :
dmdt + a*exp(Asin(wt)) * exp((2-m)^2) = 0
which is of the form of
y'(t) + f(t)y(t) = g(t)
with
y'(t) = dmdt
f(t) = a*exp(Asin(wt))
y(t) = exp((2-m)^2)
g(t) = 0
This is similar to the example 3 of the page ode45
Look how it is resolved and just adapt it to your problem.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by