call function in another function

Hi all!
I have the following problem:
I use the Runge-Kutta algorithm to solve a differential equation - the (self written) function uses as input the differential equation (function handle or anonymus function) and some initial conditions, which are not relevant for my problem here.
Example with anonymus function:
phi = rungekutta(@(y) ([y(2); -sin(y(1))]));
Example with function handle:
function dydt = myfun(y)
dydt = [y(2); -sin(y(1))];
end
and then:
phi = rungekutta(myfun);
This works without any troubles. The problem appears if my differential equation has more than one input parameter.
function dydt = myfun(y,omega)
dydt = [y(2); -omega^2*y(1)];
end
Now I want to use different values of omega, but I am not sure how to say which variable is the input and which is the one to solve for. Something like:
omega = 1;
phi = rungekutta(myfun(y, omega));
but then Matlab asks for y, altough it is only the variable to solve for.
I hope i could formulate my problem in an understandable way.
Thanks,
Stefan

Respuestas (1)

Torsten
Torsten el 2 de En. de 2023
Movida: Rik el 3 de En. de 2023
phi = rungekutta(@(y)myfun(y, omega));

1 comentario

StefSter
StefSter el 2 de En. de 2023
Movida: Rik el 3 de En. de 2023
Thank you, that was exactly what i was looking for

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Preguntada:

el 2 de En. de 2023

Movida:

Rik
el 3 de En. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by