Is there a way to pass a function handle as an argument for fsolve command?

1 次查看(过去 30 天)
I am trying to extract the fixed (equilibrium) point from a system of two ODEs. First, I constructed the function handle that holds both ODEs
F = @(t) [y(2); (R*omega^2/l)*cos(y(1) - omega*t) - (g/l)*sin(y(1))];
where R=0.5; omega = 0.25; l=1; and g=9.81;. As for omega, it is a function of theta and I managed to extract it as a vector by using ode45. I thought of using fsolve for achieving my main purpose of finding fixed points:
ye = fsolve(@F,[pi/4,pi/4]);
However, this returns an error that F is unrecognized function or variable. This leads me to think that fsolve does not accept function handles. Therefore, I hope there is a way to find fixed points either by using fsolve or via another way. Any help is appreciated.

回答(1 个)

Matt J
Matt J 2022-10-18
编辑:Matt J 2022-10-18
F is already a function handle, so the call should be something like,
F = @(y) [y(2); (R*omega^2/l)*cos(y(1) - omega*t) - (g/l)*sin(y(1))];
ye = fsolve(F,[pi/4,pi/4]);
However, it is pretty clear that for F(y)=0 that y(2)=0, so really you could have just solved for y(1) using,
f=@(y1) (R*omega^2/l)*cos(y(1) - omega*t) - (g/l)*sin(y1);
y1=fzero(f,pi/4);

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by