solve differential equation that have a time variant function and terms ode45

as the quistion says
i want to solve a diffrential equation that has the following form using ode45
where
a and b are constant
c(t) is a time deppendant term
f(x(t)) is a time deppendant function of x
g(t) is a time deppendant function
thank you.

1 Comment

Okay.What have you tried so far, which problems occur and what is your question?

Sign in to comment.

Answers (1)

That should be just what the odeNN-suite of functions are made for. Just write yourself a function where you express the 2nd order ODE as 2 coupled 1st-order:
function dxdt = myode(t,x)
a = % whatever values you have for your coefficients
b = % same difference
c = c_of_t(t);
f = f_of_x(t,x);
g = g_of_t(t);
dxdt = [x(2);
1/a*(g - b*x(2) - c*f)];
end
Where c_of_t f_of_t and g_of_t are whatever functions you need to call/define. Then simply call ode45 as in the documentation example.
HTH

Products

Release

R2018b

Tags

Asked:

on 6 Feb 2019

Answered:

on 6 Feb 2019

Community Treasure Hunt

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

Start Hunting!