How can I plug the symbol vector into function.m file for ode solving?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zhichao Shen
el 1 de Dic. de 2020
Respondida: Zhichao Shen
el 2 de Dic. de 2020
I want to solve the problem where a stage is that I need to use ode23 or ode45 to solve the time-varying variables. For instance, the varibales is nX1 space vector. So I need to build the nX1 differential equations like that
function f = ODE(t,y,Q,R,r)
f =[2*y(1) - 10*exp(-2*t) - 22*y(3) - (y(1)*(y(1)/2 + 25*y(2) - (51*y(3))/2))/(2*(t - 15)) - (25*y(2)*(y(1)/2 + 25*y(2) - (51*y(3))/2))/(t - 15) + (51*y(3)*(y(1)/2 + 25*y(2) - (51*y(3))/2))/(2*(t - 15))
51*y(2) - 60*y(3) - 11*y(6) - (y(1)*(y(2)/2 + 25*y(5) - (51*y(6))/2))/(2*(t - 15)) - (25*y(2)*(y(2)/2 + 25*y(5) - (51*y(6))/2))/(t - 15) + (51*y(3)*(y(2)/2 + 25*y(5) - (51*y(6))/2))/(2*(t - 15))
11*y(3) - 10*y(4) - 11*y(8) - (y(1)*(y(3)/2 + 25*y(6) - (51*y(8))/2))/(2*(t - 15)) - (25*y(2)*(y(3)/2 + 25*y(6) - (51*y(8))/2))/(t - 15) + (51*y(3)*(y(3)/2 + 25*y(6) - (51*y(8))/2))/(2*(t - 15))...]
Traditionally, I can solve it by using [t,y]=ode45(@ODE,tspan,InitialCondition) to find the curve of all of the variables.
My point is: Can I let the differnential equations be automatically solved as soon as I get the symbolic expression of matrix f. I have think about it for serval days already.
Thanks.
8 comentarios
Walter Roberson
el 1 de Dic. de 2020
When you build up ode equations symbolically you use symbolic functions x(t) and so on. The workflow converts the function and derivatives references into variable references so that the boundary condition vector can be indexed, and odeFunction knows to package in the form of f(t,x, additionals)
Respuesta aceptada
Ameer Hamza
el 1 de Dic. de 2020
Are you manually pasting your symboling expression in the ODE() function? You can use odetovectorfield(): https://www.mathworks.com/help/symbolic/odetovectorfield.html to solve the equations with ode45(). See the example "Solve Higher-Order Differential Equation Numerically" on the documentation page of odetovectorfield().
13 comentarios
Ameer Hamza
el 2 de Dic. de 2020
I don't think there is a good way to change that. But why does this order matter? The solution will still be the same.
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!