Borrar filtros
Borrar filtros

create vectorfield for an ODE

2 visualizaciones (últimos 30 días)
Seb
Seb el 20 de Abr. de 2011
Hello everyone, my problem is the following:
consider the differential equation x' = f(x), where f is a vector function. consider that for my problem, i have a formula to create f. given a vector a of appropriate size, f( x ) = a* (a_transpose*x). Now i want to test this differential equation with variation of a. Instead of writing f by hand, i want to have one function that has the vector a as an input and gives me the function handle of the right hand side of the ode.
But i came a cross a hard problem: you cant change a handle once its done. also, i cant write the right hand side first and declare the anonymous function because one cant just write x(1), x(2) ...
is there a easy way to figure this out?
thanks a lot

Respuesta aceptada

Jarrod Rivituso
Jarrod Rivituso el 20 de Abr. de 2011
Are you looking to have "a" change within a single call to ODE45, or would you like it to change on each subsequent call?
If the latter is the case, you could use an anonymous function wrapper to the derivative function
function dy = derivs(t,y,a)
dy = a*y;
And then
>> derivWrapper = @(t,y) derivs(t,y,5);
>> [t,y] = ode45(derivWrapper,[0 10],2)
>> plot(t,y)
If the former is the case, you could modify your derivative function to change "a" as you want to.
function dy = derivs(t,y)
if (t > 5)
a = 1;
else
a = 3;
end
dy = a*y;
  1 comentario
Seb
Seb el 20 de Abr. de 2011
thanks that sounds nice, i will try further on that.
PS: it was the ladder case :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by