problem with solving a set of equations using ODE solvers in matlab

46 Views Asked by At

I have used matlab ode solvers to solve equations of the form: $$dy/dt=f(y,t)$$ in other words, where for instance say with an explicit Euler time stepping $$y^{n+1}=y^{n}+\Delta t f(y^n,t)$$ Is it possible to use ODE solvers to (simultaneously or otherwise) solve the system of two equations in the form: $$\left\{ \begin{array}{c} x^{n+1}\\ y^{n+1} \end{array}\right\} =\left\{ \begin{array}{c} x^{n}+\Delta t\,g\left(x^{n},t\right)\\ \frac{x^{n}y^{n}+\Delta t\,f\left(y^{n},x^{n},t\right)}{x^{n+1}} \end{array}\right\} $$ where f and g are arbitrary functions, n refers to the nth time step, t is time and x and y are variables.

1

There are 1 best solutions below

7
On

Define $z=x·y$, then your second equation is $$ z^{n+1}=z^n+Δt·f(z^n/x^n,x^n,t^n) $$ resp. the Euler step for $\dot z=f(y/x,x,t)$.

Then you can solve the equation as a coupled system as usual.


If you want to get $y$ directly, use $\dot z = \dot x·y+x·\dot y$ to find $$ \dot y = \frac{f(y,x,t)-g(x,t)·y}{x} $$ as the second equation of the system.