Needing help using ode15s to solve an equation.

Hi there just needing some help using ode15s. I've never used this built-in function, but i need to use it to solve the equation below using ode15s:
I have the choice of what values to give the parameters, but i just dont know how to start coding. Has anyone got any tips to help me get started and complete this. Any suggestions or help is appreciated.

 Respuesta aceptada

I find it easiest to let the Symbolic Math Toolbox do all the heavy lifting —
syms C(t) C_in C_0 Q_in Q_out t V_0 Y
DE = (V_0 + (Q_in - Q_out)*t) * diff(C) + Q_in * C == Q_in * C_in
DE(t) = 
DE = isolate(DE, diff(C))
DE = 
VF = odeToVectorField(DE)
VF = 
DEfcn = matlabFunction(VF, 'Vars',{t,Y,C_in,Q_in,Q_out,V_0}) % Use This Result With The Numeric ODE Solvers
DEfcn = function_handle with value:
@(t,Y,C_in,Q_in,Q_out,V_0)[-(Q_in.*Y(1)-C_in.*Q_in)./(V_0+t.*(Q_in-Q_out))]
C(t) = dsolve(DE, C(0) == C_0) % Analytic Solution
C(t) = 
You can use matlabFunction with the right-hand-side of ‘C(t)’ to check the result of the numerical integration. Remember to include ‘C_0’ in the 'Vars' list.
.

6 comentarios

Ryan Marsh
Ryan Marsh el 6 de Mayo de 2022
Editada: Ryan Marsh el 6 de Mayo de 2022
Thank you very much!!!
Star Strider
Star Strider el 6 de Mayo de 2022
As always, my pleasure!
Ryan Marsh
Ryan Marsh el 6 de Mayo de 2022
Just quickly, since you have been a massive help, would you also know what would be the best way to create a simple plot to show concentraion over time. Thanks :)
Star Strider
Star Strider el 6 de Mayo de 2022
Thank you!
Yes!
The numerical ODE solvers are coded as:
[t,y] = ode15s( ... );
so to plot the results:
figure
plot(t,y)
grid
xlabel('Time')
ylabel('C(t)')
Since there is only one output, so only one column in ‘y’, no legend would be necessary. However it would be if several different vectors were plotted in the same axes for different parameter values, using a loop and the hold function.
.
Ryan Marsh
Ryan Marsh el 6 de Mayo de 2022
Thank you !!!
Star Strider
Star Strider el 6 de Mayo de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2021b

Preguntada:

el 6 de Mayo de 2022

Comentada:

el 6 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by