call function in another function
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!